#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ iter;
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int processFile(char *filename) {
  int fd;
  char buff[64 * 1024];
  int buff_size = 64 * 1024;
  int size;
  int tmp = 0;
  static iter = 0;
  if ((fd = open(filename, O_RDWR)) == -1) {
    fprintf(stderr, "Error opening file %s\n", filename);
    return 0;
  }
  while ((size = read(fd, buff, buff_size)) > 0) {
    tmp += size;
  }
  if (size == -1) {
    fprintf(stderr, "Error reading from file\n");
    close(fd);
    return 0;
  }
  sprintf(buff, "Iter %d Adding a line at the end of file %s\n", iter++,
          filename);
  write(fd, buff, strlen(buff));
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<processFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x10000,-0x10024(%rbp)
movl   $0x0,-0x1002c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d8 <processFile+0x68>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12be <processFile+0x14e>
jmp    11dd <processFile+0x6d>
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    -0x10024(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x10028(%rbp)
cmp    $0x0,%eax
jle    1218 <processFile+0xa8>
mov    -0x10028(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
jmp    11dd <processFile+0x6d>
cmpl   $0xffffffff,-0x10028(%rbp)
jne    1250 <processFile+0xe0>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    12be <processFile+0x14e>
lea    -0x10020(%rbp),%rdi
mov    0x2e03(%rip),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2df8(%rip)
mov    -0x10(%rbp),%rcx
lea    0xdbd(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1003c(%rbp)
lea    -0x10020(%rbp),%rax
mov    %rax,-0x10038(%rbp)
lea    -0x10020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1003c(%rbp),%edi
mov    -0x10038(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10000,%rsp
mov    %rdi,%r14
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11fe <processFile+0x8e>
mov    %eax,%ebx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11a0 <processFile+0x30>
cmp    $0xffffffff,%eax
je     121c <processFile+0xac>
mov    0x2ea2(%rip),%edx
lea    0x1(%rdx),%eax
mov    %eax,0x2e99(%rip)
lea    0xe62(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14,%rcx
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%ebp
jmp    123c <processFile+0xcc>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    123c <processFile+0xcc>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x10000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@processFile.iter = internal global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Error opening file %s\0A\00"
@.str.1 = [25 x i8] c"Error reading from file\0A\00"
@.str.2 = [45 x i8] c"Iter %d Adding a line at the end of file %s\0A\00"
@iter = global i64 0
define i32 @processFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [65536 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 65536, i32* %6
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 0, i32* %2
br label %49
17: ; preds = %1
br label %18
18: ; preds = %24, %17
%19 = load i32, i32* %4
%20 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @read(i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = add nsw i32 %26, %25
store i32 %27, i32* %8
br label %18
28: ; preds = %18
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 @close(i32 %34)
store i32 0, i32* %2
br label %49
36: ; preds = %28
%37 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* @processFile.iter
%39 = add nsw i32 %38, 1
store i32 %39, i32* @processFile.iter
%40 = load i8*, i8** %3
%41 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* %40)
%42 = load i32, i32* %4
%43 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
%47 = load i32, i32* %4
%48 = call i32 @close(i32 %47)
store i32 1, i32* %2
br label %49
49: ; preds = %36, %31, %13
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@processFile.iter = internal unnamed_addr global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Error opening file %s\0A\00"
@.str.1 = [25 x i8] c"Error reading from file\0A\00"
@.str.2 = [45 x i8] c"Iter %d Adding a line at the end of file %s\0A\00"
@iter = global i64 0
define i32 @processFile(i8* %0) {
%2 = alloca [65536 x i8]
%3 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
10: ; preds = %1, %10
%11 = call i32 @read(i32 %5, i8* %3, i32 65536)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = icmp eq i32 %11, -1
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @close(i32 %5)
br label %26
19: ; preds = %13
%20 = load i32, i32* @processFile.iter
%21 = add nsw i32 %20, 1
store i32 %21, i32* @processFile.iter
%22 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* %0)
%23 = call i32 @strlen(i8* %3)
%24 = call i32 @write(i32 %5, i8* %3, i32 %23)
%25 = call i32 @close(i32 %5)
br label %26
26: ; preds = %19, %15, %7
%27 = phi i32 [ 0, %7 ], [ 0, %15 ], [ 1, %19 ]
ret i32 %27
}