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


x86 assembly (clang, -O0):
<f4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <f4+0x4e>
cmpq   $0x0,-0x20(%rbp)
jne    11ab <f4+0x6b>
mov    0x2e43(%rip),%rax
movslq (%rax),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1201 <f4+0xc1>
jmp    11b0 <f4+0x70>
mov    -0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x21(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     11ef <f4+0xaf>
mov    -0x20(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11b0 <f4+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):
<f4>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rbx,%rbx
je     11ff <f4+0xaf>
mov    %rax,%r14
test   %rax,%rax
je     11ff <f4+0xaf>
lea    0xe87(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
mov    0x2e42(%rip),%r13
cmp    0x0(%r13),%rax
je     11e1 <f4+0x91>
lea    0xe66(%rip),%r15
lea    0xf(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movsbl 0xf(%rsp),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11c0 <f4+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2dd2(%rip),%rax
movslq (%rax),%rcx
lea    0xdf4(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <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"
@EOF = global i64 0
define void @f4(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 %38
22: ; preds = %14
br label %23
23: ; preds = %28, %22
%24 = load i32*, i32** %5
%25 = call i64 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%26 = load i64, i64* @EOF
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32*, i32** %6
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %23
33: ; preds = %23
%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"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i64 0
define void @f4(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 %13, label %9
9: ; preds = %2
%10 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %25, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 20, i64 1, i32* %16)
br label %28
18: ; preds = %9, %18
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = call i32 @fputc(i32 %20, i32* %5)
%22 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %18
25: ; preds = %18, %9
%26 = call i32 @fclose(i32* %4)
%27 = call i32 @fclose(i32* %5)
br label %28
28: ; preds = %25, %13
ret void
}