#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void f1(char *nameR, char *nameW) {
  FILE *fpR, *fpW;
  char c;
  fpR = fopen(nameR, "r");
  fpW = fopen(nameW, "w");
  if (fpR == NULL || fpW == NULL) {
    fprintf(stderr, "Error opening file.\n");
    return;
  }
  while (!feof(fpR)) {
    c = fgetc(fpR);
    fputc(c, fpW);
  }
  fclose(fpR);
  fclose(fpW);
  return;
}


x86 assembly (clang, -O0):
<f1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <f1+0x4e>
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <f1+0x68>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
jmp    121d <f1+0xbd>
jmp    11cd <f1+0x6d>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11eb <f1+0x8b>
jmp    120b <f1+0xab>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    11cd <f1+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f1>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rbx,%rbx
je     11c1 <f1+0x61>
mov    %rax,%r14
test   %rax,%rax
je     11c1 <f1+0x61>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11dd <f1+0x7d>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
jmp    11a0 <f1+0x40>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@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 @f1(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca 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 %37
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 %32
26: ; preds = %21
%27 = load i32*, i32** %5
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %7
%29 = load i8, i8* %7
%30 = load i32*, i32** %6
%31 = call i32 @fputc(i8 signext %29, i32* %30)
br label %21
32: ; preds = %21
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %32, %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 @f1(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 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 = icmp eq i32* %3, null
%6 = icmp eq i32* %4, null
%7 = or i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @feof(i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %22
14: ; preds = %8, %14
%15 = tail call signext i8 @fgetc(i32* %3)
%16 = tail call i32 @fputc(i8 signext %15, i32* %4)
%17 = tail call i32 @feof(i32* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %14, label %19
19: ; preds = %14, %8
%20 = tail call i32 @fclose(i32* %3)
%21 = tail call i32 @fclose(i32* %4)
br label %22
22: ; preds = %19, %11
ret void
}