#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ kill(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void assemble(const char **parts, const char *destinationDirectory) {
  FILE *resultFile = fopen(destinationDirectory, "w");
  if (!resultFile)
    kill(NULL);
  char buffer[4096];
  size_t i;
  for (i = 0; i < 5; i++) {
    FILE *currentPart = fopen(parts[i], "r");
    if (!currentPart)
      kill(NULL);
    while (!(feof(currentPart) || ferror(resultFile) || ferror(currentPart))) {
      size_t readBytes = fread(buffer, 1, 4096, currentPart);
      fwrite(buffer, 1, readBytes, resultFile);
    }
    fclose(currentPart);
  }
  fclose(resultFile);
  printf("Done!");
}


x86 assembly (clang, -O0):
<assemble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <assemble+0x3b>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <kill@plt>
movq   $0x0,-0x1028(%rbp)
cmpq   $0x5,-0x1028(%rbp)
05
jae    12e7 <assemble+0x167>
mov    -0x8(%rbp),%rax
mov    -0x1028(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe18(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    120d <assemble+0x8d>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <kill@plt>
jmp    1212 <assemble+0x92>
mov    -0x1030(%rbp),%rdi
call   1070 <feof@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x1039(%rbp)
jne    126a <assemble+0xea>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x1039(%rbp)
jne    126a <assemble+0xea>
mov    -0x1030(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1039(%rbp)
mov    -0x1039(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    127f <assemble+0xff>
jmp    12c4 <assemble+0x144>
lea    -0x1020(%rbp),%rdi
mov    -0x1030(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %rax,-0x1038(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1038(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    1212 <assemble+0x92>
mov    -0x1030(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1028(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
jmp    11c6 <assemble+0x46>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd0d(%rip),%rdi
call   1060 <printf@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assemble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe62(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11b5 <assemble+0x35>
xor    %edi,%edi
call   1080 <kill@plt>
xor    %ebp,%ebp
lea    0xe44(%rip),%r15
mov    %rsp,%r12
jmp    11e2 <assemble+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x1,%rbp
cmp    $0x5,%rbp
je     1251 <assemble+0xd1>
mov    (%r14,%rbp,8),%rdi
mov    %r15,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <assemble+0x80>
xor    %edi,%edi
call   1080 <kill@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11d0 <assemble+0x50>
mov    %r13,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11d0 <assemble+0x50>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11d0 <assemble+0x50>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r13,%rcx
call   10a0 <fwrite@plt>
jmp    1200 <assemble+0x80>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0xda4(%rip),%rdi
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Done!\00"
define void @assemble(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @kill(i32* null)
br label %16
16: ; preds = %14, %2
store i64 0, i64* %7
br label %17
17: ; preds = %57, %16
%18 = load i64, i64* %7
%19 = icmp ult i64 %18, 5
br i1 %19, label %20, label %60
20: ; preds = %17
%21 = load i8**, i8*** %3
%22 = load i64, i64* %7
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = call i32 @kill(i32* null)
br label %30
30: ; preds = %28, %20
br label %31
31: ; preds = %46, %30
%32 = load i32*, i32** %8
%33 = call i64 @feof(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %31
%36 = load i32*, i32** %5
%37 = call i64 @ferror(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32*, i32** %8
%41 = call i64 @ferror(i32* %40)
%42 = icmp ne i64 %41, 0
br label %43
43: ; preds = %39, %35, %31
%44 = phi i1 [ true, %35 ], [ true, %31 ], [ %42, %39 ]
%45 = xor i1 %44, true
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%48 = load i32*, i32** %8
%49 = call i64 @fread(i8* %47, i32 1, i32 4096, i32* %48)
store i64 %49, i64* %9
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%51 = load i64, i64* %9
%52 = load i32*, i32** %5
%53 = call i32 @fwrite(i8* %50, i32 1, i64 %51, i32* %52)
br label %31
54: ; preds = %43
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %54
%58 = load i64, i64* %7
%59 = add i64 %58, 1
store i64 %59, i64* %7
br label %17
60: ; preds = %17
%61 = load i32*, i32** %5
%62 = call i32 @fclose(i32* %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Done!\00"
define void @assemble(i8** nocapture %0, i8* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @kill(i32* null)
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
br label %10
10: ; preds = %8, %32
%11 = phi i64 [ 0, %8 ], [ %34, %32 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @kill(i32* null)
br label %18
18: ; preds = %16, %10
%19 = tail call i64 @feof(i32* %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18, %27
%22 = tail call i64 @ferror(i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = tail call i64 @ferror(i32* %14)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = call i64 @fread(i8* %9, i32 1, i32 4096, i32* %14)
%29 = call i32 @fwrite(i8* %9, i32 1, i64 %28, i32* %4)
%30 = tail call i64 @feof(i32* %14)
%31 = icmp eq i64 %30, 0
br i1 %31, label %21, label %32
32: ; preds = %24, %21, %27, %18
%33 = tail call i32 @fclose(i32* %14)
%34 = add nuw nsw i64 %11, 1
%35 = icmp eq i64 %34, 5
br i1 %35, label %36, label %10
36: ; preds = %32
%37 = tail call i32 @fclose(i32* %4)
%38 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret void
}