#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ doWrite(int, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open_input(char *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown_input(int, char *);
void write_file(int outputFd, char *inputFile) {
  int inputFd = open_input(inputFile);
  char buffer[100 + 1];
  ssize_t dataRead = 1;
  while (dataRead != 0) {
    dataRead = read(inputFd, buffer, 100);
    if (dataRead == -1) {
      perror(inputFile);
      close(inputFd);
      close(outputFd);
      exit(EXIT_FAILURE);
    } else {
      buffer[dataRead] = '\0';
      doWrite(outputFd, buffer, dataRead);
    }
  }
  shutdown_input(inputFd, inputFile);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <open_input@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     1213 <write_file+0xa3>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    11f0 <write_file+0x80>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1030 <doWrite@plt>
jmp    1198 <write_file+0x28>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <shutdown_input@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1070 <open_input@plt>
mov    %eax,%r12d
mov    %rsp,%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11d6 <write_file+0x66>
mov    %eax,%ebp
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <doWrite@plt>
test   %ebp,%ebp
jne    1190 <write_file+0x20>
mov    %r12d,%edi
mov    %r14,%rsi
call   1080 <shutdown_input@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <perror@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define void @write_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [101 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @open_input(i8* %8)
store i32 %9, i32* %5
store i32 1, i32* %7
br label %10
10: ; preds = %36, %2
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i32, i32* %5
%15 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 100)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = call i32 @perror(i8* %20)
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %13
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %3
%33 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* %7
%35 = call i32 @doWrite(i32 %32, i8* %33, i32 %34)
br label %36
36: ; preds = %28
br label %10
37: ; preds = %10
%38 = load i32, i32* %5
%39 = load i8*, i8** %4
%40 = call i32 @shutdown_input(i32 %38, i8* %39)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define void @write_file(i32 %0, i8* %1) {
%3 = alloca [101 x i8]
%4 = tail call i32 @open_input(i8* %1)
%5 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %2, %15
%7 = call i32 @read(i32 %4, i8* %5, i32 100)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = call i32 @perror(i8* %1)
%11 = call i32 @close(i32 %4)
%12 = call i32 @close(i32 %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %6
%16 = sext i32 %7 to i64
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @doWrite(i32 %0, i8* %5, i32 %7)
%19 = icmp eq i32 %7, 0
br i1 %19, label %20, label %6
20: ; preds = %15
%21 = call i32 @shutdown_input(i32 %4, i8* %1)
ret void
}