#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 */
struct passwd {
  int /*<<< orphan*/ pw_gid;
  int /*<<< orphan*/ pw_uid;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ chown(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
struct passwd *getpwnam(char *);
int copyFile(const char *sourcePath, const char *destPath) {
  FILE *sourceFile, *destFile;
  int a;
  if (!(sourceFile = fopen(sourcePath, "rb"))) {
    return -1;
  }
  if (!(destFile = fopen(destPath, "wb"))) {
    fclose(sourceFile);
    return -1;
  }
  while (1) {
    a = fgetc(sourceFile);
    if (!feof(sourceFile)) {
      fputc(a, destFile);
    } else {
      break;
    }
  }
  fclose(destFile);
  fclose(sourceFile);
  struct passwd *webUser = getpwnam("www-data");
  chown(destPath, webUser->pw_uid, webUser->pw_gid);
  return 0;
}


x86 assembly (clang, -O0):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11aa <copyFile+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <copyFile+0xea>
mov    -0x18(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11dd <copyFile+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <copyFile+0xea>
jmp    11e2 <copyFile+0x72>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    1211 <copyFile+0xa1>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1216 <copyFile+0xa6>
jmp    121b <copyFile+0xab>
jmp    11e2 <copyFile+0x72>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd2(%rip),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1080 <chown@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1207 <copyFile+0x97>
mov    %rax,%rbx
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ff <copyFile+0x8f>
mov    %rax,%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11d2 <copyFile+0x62>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
jmp    11b0 <copyFile+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe1d(%rip),%rdi
call   1060 <getpwnam@plt>
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r14,%rdi
call   1080 <chown@plt>
xor    %ebp,%ebp
jmp    1207 <copyFile+0x97>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [9 x i8] c"www-data\00"
define i32 @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 = icmp eq i32* %3, null
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @fgetc(i32* %3)
%10 = tail call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %20
12: ; preds = %5
%13 = tail call i32 @fclose(i32* %3)
br label %29
14: ; preds = %8, %14
%15 = phi i32 [ %17, %14 ], [ %9, %8 ]
%16 = tail call i32 @fputc(i32 %15, i32* %6)
%17 = tail call i32 @fgetc(i32* %3)
%18 = tail call i32 @feof(i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %14, label %20
20: ; preds = %14, %8
%21 = tail call i32 @fclose(i32* %6)
%22 = tail call i32 @fclose(i32* %3)
%23 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i32 @chown(i8* %1, i32 %25, i32 %27)
br label %29
29: ; preds = %2, %20, %12
%30 = phi i32 [ 0, %20 ], [ -1, %12 ], [ -1, %2 ]
ret i32 %30
}