#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *extract(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int parse(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  FILE *in, *out;
  char *cp, name[256], *root;
  if (argc < 3) {
    (void)fprintf(stderr, "%s synopsis:  %s file type\n", argv[0], argv[0]);
    return 1;
  }
  in = fopen(argv[1], "r");
  if (in == (FILE *)NULL) {
    (void)fprintf(stderr, "%s:  unable to read %s.\n", argv[0], argv[1]);
    return 2;
  }
  root = extract(argv[1]);
  (void)sprintf(name, "%s.%s", root, argv[2]);
  out = fopen(name, "w");
  if (out == (FILE *)NULL) {
    (void)fprintf(stderr, "%s:  unable to write %s.\n", argv[0], name);
    return 2;
  }
  return parse(in, out, argv[2]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a2 <main+0x52>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <main+0xa5>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe3a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1294 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <extract@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe11(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127c <main+0x12c>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    -0x130(%rbp),%rcx
lea    0xdd4(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1294 <main+0x144>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
call   1060 <parse@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1189 <main+0x39>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe89(%rip),%rsi
mov    %rcx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%eax
jmp    122b <main+0xdb>
mov    0x8(%rbx),%rdi
lea    0xe88(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11f2 <main+0xa2>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   1050 <extract@plt>
mov    0x10(%rbx),%rcx
lea    0xe82(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
lea    0xe73(%rip),%rsi
mov    %r15,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     120b <main+0xbb>
mov    0x10(%rbx),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <parse@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xe15(%rip),%rsi
jmp    1221 <main+0xd1>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe21(%rip),%rsi
mov    %rsp,%rcx
call   1030 <fprintf@plt>
mov    $0x2,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"%s synopsis: %s file type\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"%s: unable to read %s.\0A\00"
@.str.3 = [6 x i8] c"%s.%s\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"%s: unable to write %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %20)
store i32 1, i32* %3
br label %67
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %38
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %36)
store i32 2, i32* %3
br label %67
38: ; preds = %22
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i8* @extract(i8* %41)
store i8* %42, i8** %10
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%44 = load i8*, i8** %10
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %44, i8* %47)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %7
%51 = load i32*, i32** %7
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %60
53: ; preds = %38
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%59 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %57, i8* %58)
store i32 2, i32* %3
br label %67
60: ; preds = %38
%61 = load i32*, i32** %6
%62 = load i32*, i32** %7
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call i32 @parse(i32* %61, i32* %62, i8* %65)
store i32 %66, i32* %3
br label %67
67: ; preds = %60, %53, %29, %13
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"%s synopsis: %s file type\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"%s: unable to read %s.\0A\00"
@.str.3 = [6 x i8] c"%s.%s\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"%s: unable to write %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %8)
br label %35
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = load i8*, i8** %11
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %18)
br label %35
20: ; preds = %10
%21 = load i8*, i8** %11
%22 = tail call i8* @extract(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %24)
%26 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %1
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %30, i8* %4)
br label %35
32: ; preds = %20
%33 = load i8*, i8** %23
%34 = tail call i32 @parse(i32* %13, i32* %26, i8* %33)
br label %35
35: ; preds = %32, %28, %15, %6
%36 = phi i32 [ 1, %6 ], [ 2, %15 ], [ 2, %28 ], [ %34, %32 ]
ret i32 %36
}