#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main() {
  FILE *fp1, *fp2;
  fp1 = fopen("file1", "r");
  fp2 = fopen("file2", "w");
  while (!feof(fp1))
    putchar(getc(fp1));
  putchar(10);
  rewind(fp1);
  while (!feof(fp1))
    putc(getc(fp1), fp2);
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6b(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <main+0x5b>
jmp    11e0 <main+0x70>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11ad <main+0x3d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1211 <main+0xa1>
jmp    122a <main+0xba>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <putc@plt>
jmp    11f3 <main+0x83>
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   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe77(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11bd <main+0x4d>
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
nop
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11f0 <main+0x80>
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <putc@plt>
jmp    11d0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"file2\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %5, i32** %3
br label %6
6: ; preds = %11, %0
%7 = load i32*, i32** %2
%8 = call i32 @feof(i32* %7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32*, i32** %2
%13 = call i32 @getc(i32* %12)
%14 = call i32 @putchar(i32 %13)
br label %6
15: ; preds = %6
%16 = call i32 @putchar(i32 10)
%17 = load i32*, i32** %2
%18 = call i32 @rewind(i32* %17)
br label %19
19: ; preds = %24, %15
%20 = load i32*, i32** %2
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32*, i32** %2
%26 = call i32 @getc(i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @putc(i32 %26, i32* %27)
br label %19
29: ; preds = %19
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"file1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"file2\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 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 ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32 @feof(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0, %5
%6 = tail call i32 @getc(i32* %1)
%7 = tail call i32 @putchar(i32 %6)
%8 = tail call i32 @feof(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %5, label %10
10: ; preds = %5, %0
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @rewind(i32* %1)
%13 = tail call i32 @feof(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10, %15
%16 = tail call i32 @getc(i32* %1)
%17 = tail call i32 @putc(i32 %16, i32* %2)
%18 = tail call i32 @feof(i32* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %10
%21 = tail call i32 @fclose(i32* %1)
%22 = tail call i32 @fclose(i32* %2)
ret i32 0
}