#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ flockfile(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/ *);
int main() {
  char c;
  FILE *pin, *pout;
  pin = fopen("file.in", "r");
  pout = fopen("file.out", "w+");
  flockfile(pout);
  while ((c = fgetc(pin)) != EOF) {
    fputc(c, pout);
  }
  funlockfile(pout);
  fclose(pin);
  fclose(pout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <flockfile@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e2c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11db <main+0x7b>
mov    -0x5(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
jmp    11a6 <main+0x46>
mov    -0x18(%rbp),%rdi
call   1030 <funlockfile@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <flockfile@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e40(%rip),%r15
cmp    (%r15),%al
je     11c8 <main+0x68>
nopl   (%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11b0 <main+0x50>
mov    %rbx,%rdi
call   1030 <funlockfile@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"file.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"file.out\00"
@.str.3 = [3 x i8] c"w+\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = call i32 @flockfile(i32* %7)
br label %9
9: ; preds = %16, %0
%10 = load i32*, i32** %3
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %2
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i8, i8* %2
%18 = load i32*, i32** %4
%19 = call i32 @fputc(i8 signext %17, i32* %18)
br label %9
20: ; preds = %9
%21 = load i32*, i32** %4
%22 = call i32 @funlockfile(i32* %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

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