#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*/ alarm(int);
int /*<<< orphan*/ copy(int /*<<< orphan*/ *, int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
int transfer(int fd, char *name) {
  FILE *infile;
  if (!(infile = fopen(name, "r"))) {
    alarm(2);
    fprintf(stderr, "Unable to open file %s, %d\n", name, errno);
    alarm(0);
    return -1;
  }
  copy(infile, fd);
  fclose(infile);
  return 0;
}


x86 assembly (clang, -O0):
<transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bc <transfer+0x6c>
mov    $0x2,%edi
call   1040 <alarm@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    0x2e3d(%rip),%rax
mov    (%rax),%ecx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1040 <alarm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <transfer+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <copy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1188 <transfer+0x38>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14d,%esi
call   1050 <copy@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11bf <transfer+0x6f>
mov    $0x2,%edi
call   1040 <alarm@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
lea    0xe57(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1040 <alarm@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Unable to open file %s, %d\0A\00"
@errno = global i32 0
define i32 @transfer(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = icmp ne i32* %8, null
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = call i32 @alarm(i32 2)
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %5
%14 = load i32, i32* @errno
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14)
%16 = call i32 @alarm(i32 0)
store i32 -1, i32* %3
br label %23
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = load i32, i32* %4
%20 = call i32 @copy(i32* %18, i32 %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %17, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Unable to open file %s, %d\0A\00"
@errno = global i32 0
define i32 @transfer(i32 %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i32 @alarm(i32 2)
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %8)
%10 = tail call i32 @alarm(i32 0)
br label %14
11: ; preds = %2
%12 = tail call i32 @copy(i32* %3, i32 %0)
%13 = tail call i32 @fclose(i32* %3)
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ 0, %11 ], [ -1, %5 ]
ret i32 %15
}