#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int getpid();
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *fpin, *fpout;
  char c;
  fpin = fopen("file.in", "rt");
  fpout = fopen("file.out", "w+");
  while ((c = fgetc(fpin)) != EOF) {
    fputc(c, fpout);
  }
  fclose(fpin);
  fclose(fpout);
  printf("get pid:%d\n", getpid());
  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    0xe7e(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e35(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d2 <main+0x72>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
jmp    119d <main+0x3d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe23(%rip),%rdi
call   1050 <printf@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    0xe89(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e48(%rip),%r15
cmp    (%r15),%al
je     11c8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
jne    11b0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe31(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"file.in\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [9 x i8] c"file.out\00"
@.str.3 = [3 x i8] c"w+\00"
@EOF = global i8 0
@.str.4 = [12 x i8] c"get pid:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%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** %3
br label %7
7: ; preds = %14, %0
%8 = load i32*, i32** %2
%9 = call signext i8 @fgetc(i32* %8)
store i8 %9, i8* %4
%10 = sext i8 %9 to i32
%11 = load i8, i8* @EOF
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = load i8, i8* %4
%16 = load i32*, i32** %3
%17 = call i32 @fputc(i8 signext %15, i32* %16)
br label %7
18: ; preds = %7
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
%23 = call i32 (...) @getpid()
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"file.in\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [9 x i8] c"file.out\00"
@.str.3 = [3 x i8] c"w+\00"
@EOF = global i8 0
@.str.4 = [12 x i8] c"get pid:%d\0A\00"
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 ([3 x i8], [3 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 signext i8 @fgetc(i32* %1)
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %9, %6 ], [ %3, %0 ]
%8 = tail call i32 @fputc(i8 signext %7, i32* %2)
%9 = tail call signext i8 @fgetc(i32* %1)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %12, label %6
12: ; preds = %6, %0
%13 = tail call i32 @fclose(i32* %1)
%14 = tail call i32 @fclose(i32* %2)
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %15)
ret i32 0
}