#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
size_t fread(char *, int, int, int /*<<< orphan*/ *const);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *const);
int copy_file_internal(FILE *const src, FILE *const dst) {
  char buffer[4 * 1024];
  size_t nread;
  if (src == NULL || dst == NULL) {
    return 1;
  }
  while ((nread = fread(&buffer[0], 1, sizeof(buffer), src))) {
    if (fwrite(&buffer[0], 1, nread, dst) != nread) {
      break;
    }
  }
  return nread > 0;
}


x86 assembly (clang, -O0):
<copy_file_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1149 <copy_file_internal+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1155 <copy_file_internal+0x35>
movl   $0x1,-0x4(%rbp)
jmp    11cb <copy_file_internal+0xab>
jmp    115a <copy_file_internal+0x3a>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     11b8 <copy_file_internal+0x98>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
cmp    -0x1028(%rbp),%rax
je     11b3 <copy_file_internal+0x93>
jmp    11b8 <copy_file_internal+0x98>
jmp    115a <copy_file_internal+0x3a>
cmpq   $0x0,-0x1028(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file_internal>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    $0x1,%eax
test   %rdi,%rdi
je     118d <copy_file_internal+0x6d>
mov    %rsi,%r14
test   %rsi,%rsi
je     118d <copy_file_internal+0x6d>
mov    %rdi,%r12
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1185 <copy_file_internal+0x65>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <fwrite@plt>
cmp    %rbx,%rax
je     1150 <copy_file_internal+0x30>
xor    %eax,%eax
test   %rbx,%rbx
setne  %al
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @copy_file_internal(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 1, i32* %3
br label %33
14: ; preds = %10
br label %15
15: ; preds = %28, %14
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i64 @fread(i8* %16, i32 1, i32 4096, i32* %17)
store i64 %18, i64* %7
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = load i64, i64* %7
%23 = load i32*, i32** %5
%24 = call i64 @fwrite(i8* %21, i32 1, i64 %22, i32* %23)
%25 = load i64, i64* %7
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %20
br label %29
28: ; preds = %20
br label %15
29: ; preds = %27, %15
%30 = load i64, i64* %7
%31 = icmp ugt i64 %30, 0
%32 = zext i1 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %29, %13
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @copy_file_internal(i32* %0, i32* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32* %0, null
%6 = icmp eq i32* %1, null
%7 = or i1 %5, %6
br i1 %7, label %17, label %8
8: ; preds = %2, %11
%9 = call i64 @fread(i8* %4, i32 1, i32 4096, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i64 @fwrite(i8* %4, i32 1, i64 %9, i32* %1)
%13 = icmp eq i64 %12, %9
br i1 %13, label %8, label %14
14: ; preds = %11, %8
%15 = xor i1 %10, true
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %2, %14
%18 = phi i32 [ %16, %14 ], [ 1, %2 ]
ret i32 %18
}