#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
void f3(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)) {
    fscanf(fpR, "%c", &c);
    fprintf(fpW, "%c", c);
  }
  fclose(fpR);
  fclose(fpW);
  return;
}


x86 assembly (clang, -O0):
<f3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <f3+0x4e>
cmpq   $0x0,-0x20(%rbp)
jne    11bb <f3+0x6b>
mov    0x2e3b(%rip),%rax
movslq (%rax),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    121f <f3+0xcf>
jmp    11c0 <f3+0x70>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11de <f3+0x8e>
jmp    120d <f3+0xbd>
mov    -0x18(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    -0x21(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x20(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11c0 <f3+0x70>
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):
<f3>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rbx,%rbx
je     11f3 <f3+0x93>
mov    %rax,%r14
test   %rax,%rax
je     11f3 <f3+0x93>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11d7 <f3+0x77>
lea    0xe70(%rip),%r15
lea    0x7(%rsp),%r12
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
movsbl 0x7(%rsp),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b0 <f3+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de6(%rip),%rax
movslq (%rax),%rcx
lea    0xe00(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <fwrite@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"
@.str.3 = [3 x i8] c"%c\00"
define void @f3(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 %22
17: ; preds = %14, %2
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %40
22: ; preds = %14
br label %23
23: ; preds = %28, %22
%24 = load i32*, i32** %5
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32*, i32** %5
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%31 = load i32*, i32** %6
%32 = load i8, i8* %7
%33 = sext i8 %32 to i32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %23
35: ; preds = %23
%36 = load i32*, i32** %5
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %35, %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"
@.str.3 = [3 x i8] c"%c\00"
define void @f3(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %4, null
%7 = icmp eq i32* %5, null
%8 = or i1 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @feof(i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %24
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 20, i64 1, i32* %15)
br label %27
17: ; preds = %9, %17
%18 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = call i32 @fputc(i32 %20, i32* %5)
%22 = call i32 @feof(i32* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %17, label %24
24: ; preds = %17, %9
%25 = call i32 @fclose(i32* %4)
%26 = call i32 @fclose(i32* %5)
br label %27
27: ; preds = %24, %12
ret void
}