#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ toupper(int);
void *upper(char *name) {
  FILE *fp1, *fp2;
  int c = 1;
  fp1 = fopen(name, "r");
  fp2 = fopen(name, "r+");
  if ((fp1 == NULL) || (fp2 == NULL)) {
    perror("fopen");
    exit(1);
  }
  while (c != EOF) {
    c = fgetc(fp1);
    if (c != EOF)
      fputc(toupper(c), fp2);
  }
  fclose(fp1);
  fclose(fp2);
  return NULL;
}


x86 assembly (clang, -O0):
<upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c1 <upper+0x51>
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <upper+0x67>
lea    0xe3d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11dc <upper+0x6c>
mov    -0x1c(%rbp),%eax
mov    0x2e02(%rip),%rcx
cmp    (%rcx),%eax
je     1224 <upper+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%eax
je     121f <upper+0xaf>
mov    -0x1c(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
jmp    11dc <upper+0x6c>
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):
<upper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %r14,%r14
je     1200 <upper+0x90>
mov    %rax,%r15
test   %rax,%rax
je     1200 <upper+0x90>
mov    0x2e3c(%rip),%rbx
cmpl   $0x1,(%rbx)
je     11e3 <upper+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
je     11e3 <upper+0x73>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
cmp    (%rbx),%ebp
jne    11c0 <upper+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i32 0
define i8* @upper(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12, %1
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %5
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i32, i32* %5
%31 = call i32 @toupper(i32 %30)
%32 = load i32*, i32** %4
%33 = call i32 @fputc(i32 %31, i32* %32)
br label %34
34: ; preds = %29, %23
br label %19
35: ; preds = %19
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
ret i8* null
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i32 0
define noalias i8* @upper(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %2, null
%5 = icmp eq i32* %3, null
%6 = or i1 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %8, 1
br i1 %9, label %22, label %13
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %17
%14 = tail call i32 @fgetc(i32* %2)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = tail call i32 @toupper(i32 %14)
%19 = tail call i32 @fputc(i32 %18, i32* %3)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %14, %20
br i1 %21, label %22, label %13
22: ; preds = %13, %17, %7
%23 = tail call i32 @fclose(i32* %2)
%24 = tail call i32 @fclose(i32* %3)
ret i8* null
}