#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int main() {
  int nr1, nr2, nw;
  char buffer[512];
  FILE *fp1, *fp2, *fpOut;
  fp1 = fopen("file2.bmp", "rb");
  fp2 = fopen("file3.bmp", "rb");
  fpOut = fopen("picture.bmp", "wb");
  while (!feof(fp1) && !feof(fp2)) {
    nr1 = fread(buffer, 1, 512, fp1);
    nw = fwrite(buffer, 1, nr1, fpOut);
    if (nw != nr1) {
      printf("Error in write command!\n");
      getchar();
      exit(1);
    }
    nr2 = fread(buffer, 1, 512, fp2);
    nw = fwrite(buffer, 1, nr2, fpOut);
    if (nw != nr2) {
      printf("Error in write command!\n");
      getchar();
      exit(1);
    }
  }
  fclose(fp1);
  fclose(fp2);
  fclose(fpOut);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x220(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x229(%rbp)
jne    1219 <main+0x99>
mov    -0x220(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x229(%rbp)
mov    -0x229(%rbp),%al
test   $0x1,%al
jne    122c <main+0xac>
jmp    12ff <main+0x17f>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x228(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1293 <main+0x113>
lea    0xda9(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0xc(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x228(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     12fa <main+0x17a>
lea    0xd42(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e0 <main+0x60>
mov    -0x218(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x220(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x228(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xe6a(%rip),%rdi
lea    0xe6d(%rip),%rbx
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe56(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1273 <main+0xf3>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1273 <main+0xf3>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
cmp    %ebp,%eax
jne    1256 <main+0xd6>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
cmp    %ebp,%eax
je     11e0 <main+0x60>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"file2.bmp\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [10 x i8] c"file3.bmp\00"
@.str.3 = [12 x i8] c"picture.bmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [25 x i8] c"Error in write command!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %8
br label %12
12: ; preds = %53, %0
%13 = load i32*, i32** %6
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32*, i32** %7
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %54
23: ; preds = %21
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @fread(i8* %24, i32 1, i32 512, i32* %25)
store i32 %26, i32* %2
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %2
%29 = load i32*, i32** %8
%30 = call i32 @fwrite(i8* %27, i32 1, i32 %28, i32* %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = load i32, i32* %2
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %23
%35 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 (...) @getchar()
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %23
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%40 = load i32*, i32** %7
%41 = call i32 @fread(i8* %39, i32 1, i32 512, i32* %40)
store i32 %41, i32* %3
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%43 = load i32, i32* %3
%44 = load i32*, i32** %8
%45 = call i32 @fwrite(i8* %42, i32 1, i32 %43, i32* %44)
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %38
%50 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 (...) @getchar()
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %38
br label %12
54: ; preds = %21
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"file2.bmp\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [10 x i8] c"file3.bmp\00"
@.str.3 = [12 x i8] c"picture.bmp\00"
@.str.4 = [3 x i8] c"wb\00"
@str.6 = [24 x i8] c"Error in write command!\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %6
6: ; preds = %20, %0
%7 = tail call i32 @feof(i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = tail call i32 @feof(i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = call i32 @fread(i8* %2, i32 1, i32 512, i32* %3)
%14 = call i32 @fwrite(i8* %2, i32 1, i32 %13, i32* %5)
%15 = icmp eq i32 %14, %13
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
%18 = tail call i32 (...) @getchar()
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = call i32 @fread(i8* %2, i32 1, i32 512, i32* %4)
%22 = call i32 @fwrite(i8* %2, i32 1, i32 %21, i32* %5)
%23 = icmp eq i32 %22, %21
br i1 %23, label %6, label %24
24: ; preds = %20
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
%26 = tail call i32 (...) @getchar()
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %6, %9
%29 = tail call i32 @fclose(i32* %3)
%30 = tail call i32 @fclose(i32* %4)
%31 = tail call i32 @fclose(i32* %5)
ret i32 0
}