#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 EOF;
int EXIT_FAILURE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int main() {
  FILE *fp_in, *fp_out;
  char *input_file = "image1.jpg";
  char *output_file = "image2.jpg";
  int ch;
  fp_in = fopen(input_file, "rb");
  if (fp_in == NULL) {
    perror("File opening failed");
    return EXIT_FAILURE;
  }
  fp_out = fopen(output_file, "wb");
  while (1) {
    ch = fgetc(fp_in);
    if (ch == EOF) {
      break;
    }
    fputc(ch, fp_out);
  }
  fclose(fp_in);
  fclose(fp_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b1 <main+0x61>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1212 <main+0xc2>
mov    -0x28(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%eax
jne    11e8 <main+0x98>
jmp    11f9 <main+0xa9>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11c5 <main+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cf <main+0x7f>
mov    %rax,%r14
lea    0xe94(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e53(%rip),%r15
cmp    (%r15),%eax
je     11b7 <main+0x67>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    11a0 <main+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
jmp    11c9 <main+0x79>

LLVM IR (-O0):
@.str = [11 x i8] c"image1.jpg\00"
@.str.1 = [11 x i8] c"image2.jpg\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"File opening failed\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %1
br label %33
14: ; preds = %0
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %16, i32** %3
br label %17
17: ; preds = %14, %24
%18 = load i32*, i32** %2
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
br label %28
24: ; preds = %17
%25 = load i32, i32* %6
%26 = load i32*, i32** %3
%27 = call i32 @fputc(i32 %25, i32* %26)
br label %17
28: ; preds = %23
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %1
br label %33
33: ; preds = %28, %11
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [11 x i8] c"image1.jpg\00"
@.str.1 = [11 x i8] c"image2.jpg\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"File opening failed\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
br label %20
6: ; preds = %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @fgetc(i32* %1)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %6, %11
%12 = phi i32 [ %14, %11 ], [ %8, %6 ]
%13 = tail call i32 @fputc(i32 %12, i32* %7)
%14 = tail call i32 @fgetc(i32* %1)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %11
17: ; preds = %11, %6
%18 = tail call i32 @fclose(i32* %1)
%19 = tail call i32 @fclose(i32* %7)
br label %20
20: ; preds = %17, %3
%21 = phi i32 [ %5, %3 ], [ 0, %17 ]
ret i32 %21
}