#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void f2(char *nameR, char *nameW) {
  FILE *fpR, *fpW;
  char buffer[1024 + 1];
  fpR = fopen(nameR, "r");
  fpW = fopen(nameW, "w");
  if (fpR == NULL || fpW == NULL) {
    fprintf(stderr, "Error opening file.\n");
    return;
  }
  while (!feof(fpR)) {
    fgets(buffer, 1024, fpR);
    fputs(buffer, fpW);
  }
  fclose(fpR);
  fclose(fpW);
  return;
}


x86 assembly (clang, -O0):
<f2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <f2+0x51>
cmpq   $0x0,-0x20(%rbp)
jne    11cb <f2+0x6b>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
jmp    122a <f2+0xca>
jmp    11d0 <f2+0x70>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ee <f2+0x8e>
jmp    1218 <f2+0xb8>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
jmp    11d0 <f2+0x70>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r14
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rbx,%rbx
je     11f4 <f2+0x94>
mov    %rax,%r14
test   %rax,%rax
je     11f4 <f2+0x94>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11d7 <f2+0x77>
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11b0 <f2+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
define void @f2(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1025 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 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 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14, %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %38
20: ; preds = %14
br label %21
21: ; preds = %26, %20
%22 = load i32*, i32** %5
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %5
%29 = call i32 @fgets(i8* %27, i32 1024, i32* %28)
%30 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32 @fputs(i8* %30, i32* %31)
br label %21
33: ; preds = %21
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
br label %38
38: ; preds = %33, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
define void @f2(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [1025 x i8]
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %5, null
%8 = icmp eq i32* %6, null
%9 = or i1 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @feof(i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %24
16: ; preds = %10, %16
%17 = call i32 @fgets(i8* %4, i32 1024, i32* %5)
%18 = call i32 @fputs(i8* %4, i32* %6)
%19 = call i32 @feof(i32* %5)
%20 = icmp eq i32 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %16, %10
%22 = call i32 @fclose(i32* %5)
%23 = call i32 @fclose(i32* %6)
br label %24
24: ; preds = %21, %13
ret void
}