#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void copy_userblock(char *outfilename, char *infilename) {
  FILE *fout = fopen(outfilename, "rb+");
  FILE *fin = fopen(infilename, "r");
  rewind(fout);
  int c;
  do {
    c = fgetc(fin);
    if (c != EOF)
      fputc((char)c, fout);
  } while (c != EOF);
  fclose(fin);
  fclose(fout);
}


x86 assembly (clang, -O0):
<copy_userblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11be <copy_userblock+0x6e>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11c3 <copy_userblock+0x73>
mov    -0x24(%rbp),%eax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jne    1191 <copy_userblock+0x41>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_userblock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <rewind@plt>
mov    0x2e5e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
je     11ae <copy_userblock+0x5e>
mov    %eax,%ebp
movsbl %bpl,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
cmp    (%rbx),%ebp
jne    1190 <copy_userblock+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @copy_userblock(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %5
%13 = call i32 @rewind(i32* %12)
br label %14
14: ; preds = %26, %2
%15 = load i32*, i32** %6
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i32, i32* %7
%22 = trunc i32 %21 to i8
%23 = load i32*, i32** %5
%24 = call i32 @fputc(i8 signext %22, i32* %23)
br label %25
25: ; preds = %20, %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %14, label %30
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @copy_userblock(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @rewind(i32* %3)
br label %6
6: ; preds = %10, %2
%7 = tail call i32 @fgetc(i32* %4)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = trunc i32 %7 to i8
%12 = tail call i32 @fputc(i8 signext %11, i32* %3)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %7, %13
br i1 %14, label %15, label %6
15: ; preds = %6, %10
%16 = tail call i32 @fclose(i32* %4)
%17 = tail call i32 @fclose(i32* %3)
ret void
}