#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int doTest(char *fv1, char *fv2, int siz) {
  int dskrFV1 = open(fv1, O_RDONLY);
  int dskrFV2 = open(fv2, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  if (dskrFV1 == -1) {
    printf("Failed to open a file %s\n", fv1);
    exit(1);
  }
  if (dskrFV2 == -1) {
    printf("Failed to create or trunicate a file: %s\n", fv2);
    exit(1);
  }
  char buf[siz + 1];
  read(dskrFV1, buf, siz);
  write(dskrFV2, buf, siz);
  close(dskrFV1);
  close(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
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11dc <doTest+0x7c>
mov    -0x8(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1200 <doTest+0xa0>
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
call   1060 <read@plt>
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%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
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    0x2e32(%rip),%rcx
mov    0x2e63(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%r12d
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%r12d
je     1214 <doTest+0xb4>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1220 <doTest+0xc0>
lea    0x1(%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <read@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde5(%rip),%rdi
mov    %r13,%rsi
jmp    122a <doTest+0xca>
lea    0xdf3(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [26 x i8] c"Failed to open a file %s\0A\00"
@.str.1 = [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 = load i32, i32* @O_RDONLY
%13 = call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i8*, i8** %5
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 (i8*, i32, ...) @open(i8* %14, i32 %19, i32 420)
store i32 %20, i32* %8
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %3
%24 = load i8*, i8** %4
%25 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %3
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = zext i32 %36 to i64
%38 = call i8* @llvm.stacksave()
store i8* %38, i8** %9
%39 = alloca i8, i64 %37
store i64 %37, i64* %10
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = call i32 @read(i32 %40, i8* %39, i32 %41)
%43 = load i32, i32* %8
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %43, i8* %39, i32 %44)
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = load i32, i32* %8
%49 = call i32 @close(i32 %48)
%50 = load i8*, i8** %9
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [26 x i8] c"Failed to open a file %s\0A\00"
@.str.1 = [42 x i8] c"Failed to create or trunicate a file: %s\0A\00"
define i32 @doTest(i8* %0, i8* %1, i32 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %4)
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %10, i32 420)
%12 = icmp eq i32 %5, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = icmp eq i32 %11, -1
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %16
%22 = add nsw i32 %2, 1
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
%25 = call i32 @read(i32 %5, i8* %24, i32 %2)
%26 = call i32 @write(i32 %11, i8* %24, i32 %2)
%27 = tail call i32 @close(i32 %5)
%28 = tail call i32 @close(i32 %11)
ret i32 0
}