#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int doTest(char *fv1, char *fv2, int siz) {
  FILE *dskrFV1 = fopen(fv1, "r");
  FILE *dskrFV2 = fopen(fv2, "wb");
  if (dskrFV1 == NULL) {
    printf("Failed to open a file %s\n", fv1);
    exit(1);
  }
  if (dskrFV2 == NULL) {
    printf("Failed to create or trunicate a file: %s\n", fv2);
    exit(1);
  }
  char buf[siz + 1];
  fread((void *)buf, siz, 1, dskrFV1);
  fwrite((void *)buf, siz, 1, dskrFV2);
  fclose(dskrFV1);
  fclose(dskrFV2);
  return 0;
}


x86 assembly (clang, -O0):
<doTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <doTest+0x60>
mov    -0x8(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11e5 <doTest+0x85>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doTest>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %r15,%r15
je     11fe <doTest+0x9e>
mov    %rax,%r12
test   %rax,%rax
je     120a <doTest+0xaa>
lea    0x1(%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe00(%rip),%rdi
mov    %r13,%rsi
jmp    1214 <doTest+0xb4>
lea    0xe0e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [26 x i8] c"Failed to open a file %s\0A\00"
@.str.3 = [42 x i8] c"Failed to create or trunicate a file: %s\0A\00"
define i32 @doTest(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %8
%15 = load i32*, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %9
%33 = alloca i8, i64 %31
store i64 %31, i64* %10
%34 = load i32, i32* %6
%35 = load i32*, i32** %7
%36 = call i32 @fread(i8* %33, i32 %34, i32 1, i32* %35)
%37 = load i32, i32* %6
%38 = load i32*, i32** %8
%39 = call i32 @fwrite(i8* %33, i32 %37, i32 1, i32* %38)
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %9
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [26 x i8] c"Failed to open a file %s\0A\00"
@.str.3 = [42 x i8] c"Failed to create or trunicate a file: %s\0A\00"
define i32 @doTest(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %4, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = icmp eq i32* %5, null
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %10
%16 = add nsw i32 %2, 1
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = call i32 @fread(i8* %18, i32 %2, i32 1, i32* %4)
%20 = call i32 @fwrite(i8* %18, i32 %2, i32 1, i32* %5)
%21 = tail call i32 @fclose(i32* %4)
%22 = tail call i32 @fclose(i32* %5)
ret i32 0
}