#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s [w|r]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  FILE *fp = fopen("testfile", argv[1]);
  if (fp == NULL) {
    fprintf(stderr, "Error opening file: testfile\n");
    exit(EXIT_FAILURE);
  }
  if (strcmp("w", argv[1]) == 0) {
    int i;
    for (i = 0; i < 100; i++) {
      fprintf(fp, "%3d: AAAAAAAAAAAAAAAAAAAAAAAA\n", i);
    }
  } else if (strcmp("r", argv[1]) == 0) {
    char buf[1024];
    fgets(buf, 1024, fp);
    printf("%s", buf);
  } else {
    fprintf(stderr, "Usage: %s [w|r]\n", argv[0]);
    fclose(fp);
    exit(EXIT_FAILURE);
  }
  while (1) {
  }
  fclose(fp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x4f>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe43(%rip),%rdi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1207 <main+0x97>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe22(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0xf0>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    125b <main+0xeb>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
mov    -0x1c(%rbp),%edx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122c <main+0xbc>
jmp    12e5 <main+0x175>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdea(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ab <main+0x13b>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x420(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
jmp    12e0 <main+0x170>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12e5 <main+0x175>
jmp    12ea <main+0x17a>
jmp    12ea <main+0x17a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1222 <main+0xb2>
mov    0x8(%r14),%rsi
lea    0xe7f(%rip),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123e <main+0xce>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
lea    0xe8a(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f5 <main+0x85>
mov    0x8(%r14),%rsi
lea    0xe96(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1257 <main+0xe7>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
lea    0xe70(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
jmp    1220 <main+0xb0>
lea    0xe3e(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1200 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
jmp    1220 <main+0xb0>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdcb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1279 <main+0x109>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1279 <main+0x109>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd96(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s [w|r]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"testfile\00"
@.str.2 = [30 x i8] c"Error opening file: testfile\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"%3d: AAAAAAAAAAAAAAAAAAAAAAAA\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %19
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %31
store i32 0, i32* %7
br label %38
38: ; preds = %46, %37
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 100
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i32*, i32** %6
%43 = ptrtoint i32* %42 to i32
%44 = load i32, i32* %7
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %41
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %38
49: ; preds = %38
br label %73
50: ; preds = %31
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%58 = load i32*, i32** %6
%59 = call i32 @fgets(i8* %57, i32 1024, i32* %58)
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%61 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %60)
br label %72
62: ; preds = %50
%63 = load i32, i32* @stderr
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %56
br label %73
73: ; preds = %72, %49
br label %74
74: ; preds = %73, %74
br label %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s [w|r]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"testfile\00"
@.str.2 = [30 x i8] c"Error opening file: testfile\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"%3d: AAAAAAAAAAAAAAAAAAAAAAAA\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %11
%22 = load i8*, i8** %12
%23 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = ptrtoint i32* %14 to i64
%27 = trunc i64 %26 to i32
br label %28
28: ; preds = %25, %28
%29 = phi i32 [ 0, %25 ], [ %31, %28 ]
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, 100
br i1 %32, label %41, label %28
33: ; preds = %21
%34 = load i8*, i8** %12
%35 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = call i32 @fgets(i8* %38, i32 1024, i32* %14)
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %38)
br label %41
41: ; preds = %28, %37
br label %49
42: ; preds = %33
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %1
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %44)
%46 = tail call i32 @fclose(i32* %14)
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %41, %49
br label %49
}