#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 EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, 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 *);
int main() {
  char *files[] = {"Part-1.jpg", "Part-2.jpg", "Part-3.jpg", "Part-4.jpg",
                   "Part-5.jpg"};
  FILE *resultFile = fopen("merged.jpg", "w");
  if (!resultFile)
    kill(NULL);
  char buffer[8192];
  size_t i;
  for (i = 0; i < 5; i++) {
    FILE *currentPart = fopen(files[i], "r");
    if (!currentPart)
      kill(NULL);
    while (!(feof(currentPart) || ferror(resultFile) || ferror(currentPart))) {
      size_t readBytes = fread(buffer, 1, 8192, currentPart);
      fwrite(buffer, 1, readBytes, resultFile);
    }
    fclose(currentPart);
  }
  fclose(resultFile);
  printf("Done!");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    0xe47(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1214 <main+0x84>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <kill@plt>
movq   $0x0,-0x2048(%rbp)
cmpq   $0x5,-0x2048(%rbp)
05
jae    133d <main+0x1ad>
mov    -0x2048(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
lea    0xe04(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x2050(%rbp)
cmpq   $0x0,-0x2050(%rbp)
jne    1263 <main+0xd3>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <kill@plt>
jmp    1268 <main+0xd8>
mov    -0x2050(%rbp),%rdi
call   1080 <feof@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2059(%rbp)
jne    12c0 <main+0x130>
mov    -0x38(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2059(%rbp)
jne    12c0 <main+0x130>
mov    -0x2050(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2059(%rbp)
mov    -0x2059(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    12d5 <main+0x145>
jmp    131a <main+0x18a>
lea    -0x2040(%rbp),%rdi
mov    -0x2050(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %rax,-0x2058(%rbp)
lea    -0x2040(%rbp),%rdi
mov    -0x2058(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
jmp    1268 <main+0xd8>
mov    -0x2050(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2048(%rbp)
jmp    121f <main+0x8f>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xcf9(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2030,%rsp
lea    0xe69(%rip),%rbx
mov    %rbx,(%rsp)
lea    0xe69(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe68(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe67(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe66(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe65(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11ed <main+0x6d>
xor    %edi,%edi
call   1080 <kill@plt>
xor    %r13d,%r13d
lea    0xe4d(%rip),%r14
lea    0x30(%rsp),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1220 <main+0xa0>
xor    %edi,%edi
call   1080 <kill@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1280 <main+0x100>
mov    %r12,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1280 <main+0x100>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1280 <main+0x100>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
jmp    1220 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x1,%r13
cmp    $0x5,%r13
je     129b <main+0x11b>
mov    (%rsp,%r13,8),%rbx
jmp    1200 <main+0x80>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xd9c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
add    $0x2030,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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