#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int copy_file_raw(FILE *src, FILE *dest) {
  unsigned char buffer;
  size_t fread_src_length;
  size_t fwrite_dest_length;
  if (src == NULL || dest == NULL)
    return -1;
  rewind(src);
  rewind(dest);
  while ((fread_src_length = fread(&buffer, 1, 1, src)) > 0) {
    fwrite_dest_length = fwrite(&buffer, 1, fread_src_length, dest);
    if (fwrite_dest_length < fread_src_length) {
      do {
        perror("fwrite");
        exit(EXIT_FAILURE);
      } while (0);
      ;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_file_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <copy_file_raw+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1182 <copy_file_raw+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <copy_file_raw+0xb9>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jbe    1202 <copy_file_raw+0xb2>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11fd <copy_file_raw+0xad>
jmp    11e3 <copy_file_raw+0x93>
lea    0xe16(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1194 <copy_file_raw+0x44>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file_raw>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11d1 <copy_file_raw+0x81>
mov    %rsi,%r14
test   %rsi,%rsi
je     11d1 <copy_file_raw+0x81>
mov    %rdi,%r15
call   1040 <rewind@plt>
mov    %r14,%rdi
call   1040 <rewind@plt>
lea    0x7(%rsp),%r12
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11cf <copy_file_raw+0x7f>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    %rbx,%rax
jae    1180 <copy_file_raw+0x30>
lea    0xe44(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fwrite\00"
@EXIT_FAILURE = global i32 0
define i32 @copy_file_raw(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %39
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i32 @rewind(i32* %16)
%18 = load i32*, i32** %5
%19 = call i32 @rewind(i32* %18)
br label %20
20: ; preds = %37, %15
%21 = load i32*, i32** %4
%22 = call i64 @fread(i8* %6, i32 1, i32 1, i32* %21)
store i64 %22, i64* %7
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i64, i64* %7
%26 = load i32*, i32** %5
%27 = call i64 @fwrite(i8* %6, i32 1, i64 %25, i32* %26)
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = load i64, i64* %7
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %24
br label %32
32: ; preds = %31
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; No predecessors!
br label %37
37: ; preds = %36, %24
br label %20
38: ; preds = %20
store i32 0, i32* %3
br label %39
39: ; preds = %38, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"fwrite\00"
@EXIT_FAILURE = global i32 0
define i32 @copy_file_raw(i32* %0, i32* %1) {
%3 = alloca i8
%4 = icmp eq i32* %0, null
%5 = icmp eq i32* %1, null
%6 = or i1 %4, %5
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call i32 @rewind(i32* %0)
%9 = tail call i32 @rewind(i32* %1)
br label %10
10: ; preds = %13, %7
%11 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = call i64 @fwrite(i8* %3, i32 1, i64 %11, i32* %1)
%15 = icmp ult i64 %14, %11
br i1 %15, label %16, label %10
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10, %2
%21 = phi i32 [ -1, %2 ], [ 0, %10 ]
ret i32 %21
}