#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 *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *filename = argv[1];
  char *text;
  text = calloc(1024 + 1, sizeof(char));
  if (text == NULL) {
    printf("error with calloc\n");
    return (1);
  }
  if (argc <= 1) {
    printf("usage: race <filename>\n");
    return (1);
  }
  printf("attempting to read file: '%s'...", filename);
  fflush(stdout);
  while (fp == NULL)
    fp = fopen(filename, "r");
  printf("\n");
  printf("race: GOT IT!  now watching...\n");
  while (1) {
    char *p = fgets(text, 1024, fp);
    if (p == NULL)
      continue;
    printf("%s", text);
  }
  fclose(fp);
  free(text);
  return (0);
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x401,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11aa <main+0x5a>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126b <main+0x11b>
cmpl   $0x1,-0x8(%rbp)
jg     11ce <main+0x7e>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126b <main+0x11b>
mov    -0x20(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1212 <main+0xc2>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    11ee <main+0x9e>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1254 <main+0x104>
jmp    122e <main+0xde>
mov    -0x28(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122e <main+0xde>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    $0x401,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     118c <main+0x2c>
cmp    $0x2,%ebp
jge    11a2 <main+0x42>
lea    0xeb9(%rip),%rdi
jmp    1193 <main+0x33>
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rax,%rbx
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe40(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11f0 <main+0x90>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f0 <main+0x90>

LLVM IR (-O0):
@.str = [19 x i8] c"error with calloc\0A\00"
@.str.1 = [24 x i8] c"usage: race <filename>\0A\00"
@.str.2 = [33 x i8] c"attempting to read file: '%s'...\00"
@stdout = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [32 x i8] c"race: GOT IT! now watching...\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %7
%13 = call i8* @calloc(i32 1025, i32 1)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %47
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
br label %28
28: ; preds = %31, %23
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %6
br label %28
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %34, %43, %44
%38 = load i8*, i8** %8
%39 = load i32*, i32** %6
%40 = call i8* @fgets(i8* %38, i32 1024, i32* %39)
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %37
br label %37
44: ; preds = %37
%45 = load i8*, i8** %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %45)
br label %37
47: ; preds = %21, %16
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str.2 = [33 x i8] c"attempting to read file: '%s'...\00"
@stdout = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@str = [31 x i8] c"race: GOT IT! now watching...\00"
@str.7 = [23 x i8] c"usage: race <filename>\00"
@str.8 = [18 x i8] c"error with calloc\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call dereferenceable_or_null(1025) i8* @calloc(i32 1025, i32 1)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = icmp slt i32 %0, 2
br i1 %8, label %21, label %9
9: ; preds = %7
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%11 = load i32, i32* @stdout
%12 = tail call i32 @fflush(i32 %11)
%13 = tail call i32 @putchar(i32 10)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %18, %9
%16 = tail call i8* @fgets(i8* %5, i32 1024, i32* undef)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15, %19
br label %15
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %18
21: ; preds = %7, %2
%22 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0), %2 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0), %7 ]
%23 = tail call i32 @puts(i8* dereferenceable(1) %22)
ret i32 1
}