#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 EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char ctemp;
  FILE *fp;
  int itemp, rc;
  if (argc != 2) {
    fprintf(stdout, "\n usage : filename");
    return (0);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "\n unable to open file %s\n", argv[1]);
  }
  while (1) {
    rc = fscanf(fp, "%d%c", &itemp, &ctemp);
    if (rc != 2) {
      fprintf(stdout, "\n error, rc = %d", rc);
      break;
    }
    fprintf(stdout, "\n itemp = '%d', ctemp = '%c'", itemp, ctemp);
    if (ctemp == '\n') {
      fprintf(stdout, "\n newline");
    }
    if (ctemp == EOF) {
      fprintf(stdout, "\n end of file");
      break;
    }
  }
  return (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1173 <main+0x43>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127d <main+0x14d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b4 <main+0x84>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b9 <main+0x89>
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x11(%rbp),%rcx
call   1030 <fscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
je     11fd <main+0xcd>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1276 <main+0x146>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
movsbl -0x11(%rbp),%ecx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    123f <main+0x10f>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movsbl -0x11(%rbp),%eax
mov    0x2d9e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1271 <main+0x141>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1276 <main+0x146>
jmp    11b9 <main+0x89>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11f6 <main+0xc6>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117a <main+0x4a>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x4(%rsp),%r15
lea    0x3(%rsp),%r12
mov    0x2e45(%rip),%rbp
lea    0xeb3(%rip),%r13
mov    0x2e4f(%rip),%r14
jmp    11a5 <main+0x75>
nopl   0x0(%rax,%rax,1)
cmp    (%r14),%al
je     1211 <main+0xe1>
mov    %rbx,%rdi
lea    0xe80(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <fscanf@plt>
mov    0x0(%rbp),%edi
cmp    $0x2,%eax
jne    1224 <main+0xf4>
mov    0x4(%rsp),%edx
movsbl 0x3(%rsp),%ecx
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl 0x3(%rsp),%eax
cmp    $0xa,%al
jne    11a0 <main+0x70>
mov    0x0(%rbp),%edi
lea    0xe7a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl 0x3(%rsp),%eax
jmp    11a0 <main+0x70>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1239 <main+0x109>
mov    0x0(%rbp),%edi
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1234 <main+0x104>
lea    0xe09(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [19 x i8] c"\0A usage : filename\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"\0A unable to open file %s\0A\00"
@.str.3 = [5 x i8] c"%d%c\00"
@.str.4 = [17 x i8] c"\0A error, rc = %d\00"
@.str.5 = [29 x i8] c"\0A itemp = '%d', ctemp = '%c'\00"
@.str.6 = [10 x i8] c"\0A newline\00"
@EOF = global i8 0
@.str.7 = [14 x i8] c"\0A end of file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stdout
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %60
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %21, %15
br label %28
28: ; preds = %27, %58
%29 = load i32*, i32** %7
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %8, i8* %6)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 2
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stdout
%35 = load i32, i32* %9
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %59
37: ; preds = %28
%38 = load i32, i32* @stdout
%39 = load i32, i32* %8
%40 = load i8, i8* %6
%41 = sext i8 %40 to i32
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %41)
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = load i32, i32* @stdout
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %46, %37
%50 = load i8, i8* %6
%51 = sext i8 %50 to i32
%52 = load i8, i8* @EOF
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = load i32, i32* @stdout
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %59
58: ; preds = %49
br label %28
59: ; preds = %55, %33
store i32 1, i32* %3
br label %60
60: ; preds = %59, %12
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [19 x i8] c"\0A usage : filename\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"\0A unable to open file %s\0A\00"
@.str.3 = [5 x i8] c"%d%c\00"
@.str.4 = [17 x i8] c"\0A error, rc = %d\00"
@.str.5 = [29 x i8] c"\0A itemp = '%d', ctemp = '%c'\00"
@.str.6 = [10 x i8] c"\0A newline\00"
@EOF = global i8 0
@.str.7 = [14 x i8] c"\0A end of file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %44
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 %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %10
br label %20
20: ; preds = %19, %37
%21 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %4, i8* %3)
%22 = icmp eq i32 %21, 2
%23 = load i32, i32* @stdout
br i1 %22, label %26, label %24
24: ; preds = %20
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %44
26: ; preds = %20
%27 = load i32, i32* %4
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %29)
%31 = load i8, i8* %3
%32 = icmp eq i8 %31, 10
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* @stdout
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%36 = load i8, i8* %3
br label %37
37: ; preds = %33, %26
%38 = phi i8 [ %36, %33 ], [ %31, %26 ]
%39 = load i8, i8* @EOF
%40 = icmp eq i8 %38, %39
br i1 %40, label %41, label %20
41: ; preds = %37
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %44
44: ; preds = %24, %41, %7
%45 = phi i32 [ 0, %7 ], [ 1, %41 ], [ 1, %24 ]
ret i32 %45
}