#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int sclient_copyfile(char *sname, char *dname) {
  FILE *inf, *outf;
  int c, len = 0;
  inf = fopen(sname, "rb");
  outf = fopen(dname, "wb");
  if (inf && outf) {
    for (;;) {
      c = fgetc(inf);
      if (c == EOF)
        break;
      fputc(c, outf);
      len++;
    }
  }
  if (inf)
    fclose(inf);
  if (outf)
    fclose(outf);
  return len;
}


x86 assembly (clang, -O0):
<sclient_copyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dc <sclient_copyfile+0x9c>
cmpq   $0x0,-0x20(%rbp)
je     11dc <sclient_copyfile+0x9c>
jmp    119a <sclient_copyfile+0x5a>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
jne    11bd <sclient_copyfile+0x7d>
jmp    11d7 <sclient_copyfile+0x97>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119a <sclient_copyfile+0x5a>
jmp    11dc <sclient_copyfile+0x9c>
cmpq   $0x0,-0x18(%rbp)
je     11f0 <sclient_copyfile+0xb0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1204 <sclient_copyfile+0xc4>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sclient_copyfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea3(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %ebp,%ebp
test   %rbx,%rbx
je     11aa <sclient_copyfile+0x6a>
test   %r14,%r14
je     11aa <sclient_copyfile+0x6a>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e62(%rip),%r15
cmp    (%r15),%eax
je     11aa <sclient_copyfile+0x6a>
xor    %ebp,%ebp
nopl   (%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1190 <sclient_copyfile+0x50>
test   %rbx,%rbx
je     11b7 <sclient_copyfile+0x77>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     11c4 <sclient_copyfile+0x84>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @sclient_copyfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %33
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %33
18: ; preds = %15
br label %19
19: ; preds = %26, %18
%20 = load i32*, i32** %5
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %19
br label %32
26: ; preds = %19
%27 = load i32, i32* %7
%28 = load i32*, i32** %6
%29 = call i32 @fputc(i32 %27, i32* %28)
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %19
32: ; preds = %25
br label %33
33: ; preds = %32, %15, %2
%34 = load i32*, i32** %5
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %33
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %8
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @sclient_copyfile(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp ne i32* %3, null
%6 = icmp ne i32* %4, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = tail call i32 @fgetc(i32* %3)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %20, label %12
12: ; preds = %8, %12
%13 = phi i32 [ %17, %12 ], [ %9, %8 ]
%14 = phi i32 [ %16, %12 ], [ 0, %8 ]
%15 = tail call i32 @fputc(i32 %13, i32* %4)
%16 = add nuw nsw i32 %14, 1
%17 = tail call i32 @fgetc(i32* %3)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %12
20: ; preds = %12, %8, %2
%21 = phi i32 [ 0, %2 ], [ 0, %8 ], [ %16, %12 ]
br i1 %5, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @fclose(i32* %3)
br label %24
24: ; preds = %22, %20
br i1 %6, label %25, label %27
25: ; preds = %24
%26 = tail call i32 @fclose(i32* %4)
br label %27
27: ; preds = %25, %24
ret i32 %21
}