#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 */
char EOF;
int /*<<< orphan*/ SEEK_SET;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int copy_temp(FILE *temp, FILE *file) {
  int result = EOF;
  char ch;
  if ((temp != NULL) && (file != NULL)) {
    fseek(temp, 0, SEEK_SET);
    ch = fgetc(temp);
    while (ch != EOF) {
      fputc(ch, file);
      ch = fgetc(temp);
    }
    result = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<copy_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c0 <copy_temp+0x90>
cmpq   $0x0,-0x10(%rbp)
je     11c0 <copy_temp+0x90>
mov    -0x8(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
mov    0x2e5a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11b9 <copy_temp+0x89>
mov    -0x15(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x15(%rbp)
jmp    1183 <copy_temp+0x53>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_temp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eaa(%rip),%r15
movsbl (%r15),%r14d
test   %rdi,%rdi
je     118a <copy_temp+0x5a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     118a <copy_temp+0x5a>
mov    %rdi,%rbp
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
xor    %esi,%esi
call   1050 <fseek@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%al
je     118a <copy_temp+0x5a>
movsbl %al,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    1170 <copy_temp+0x40>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@SEEK_SET = global i32 0
define i32 @copy_temp(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i8, i8* @EOF
%8 = sext i8 %7 to i32
store i32 %8, i32* %5
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %33
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %3
%19 = call signext i8 @fgetc(i32* %18)
store i8 %19, i8* %6
br label %20
20: ; preds = %26, %14
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8, i8* %6
%28 = load i32*, i32** %4
%29 = call i32 @fputc(i8 signext %27, i32* %28)
%30 = load i32*, i32** %3
%31 = call signext i8 @fgetc(i32* %30)
store i8 %31, i8* %6
br label %20
32: ; preds = %20
store i32 0, i32* %5
br label %33
33: ; preds = %32, %11, %2
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@EOF = global i8 0
@SEEK_SET = global i32 0
define i32 @copy_temp(i32* %0, i32* %1) {
%3 = load i8, i8* @EOF
%4 = sext i8 %3 to i32
%5 = icmp ne i32* %0, null
%6 = icmp ne i32* %1, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %0, i32 0, i32 %9)
%11 = tail call signext i8 @fgetc(i32* %0)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %8, %14
%15 = phi i8 [ %17, %14 ], [ %11, %8 ]
%16 = tail call i32 @fputc(i8 signext %15, i32* %1)
%17 = tail call signext i8 @fgetc(i32* %0)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %8, %2
%21 = phi i32 [ %4, %2 ], [ 0, %8 ], [ 0, %14 ]
ret i32 %21
}