#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isupper(int);
int /*<<< orphan*/ putc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ tolower(int);
int /*<<< orphan*/ toupper(int);
int main() {
  FILE *fp;
  FILE *fout;
  char *filename = "goods.txt";
  char *outfile = "goods2.txt";
  int ch;
  fp = fopen(filename, "r");
  fout = fopen(outfile, "w");
  while ((ch = fgetc(fp)) != EOF) {
    if (isupper(ch)) {
      putc(tolower(ch), fout);
    } else {
      putc(toupper(ch), fout);
    }
  }
  fclose(fp);
  fclose(fout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
je     121a <main+0xaa>
mov    -0x2c(%rbp),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     1202 <main+0x92>
mov    -0x2c(%rbp),%edi
call   1070 <tolower@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <putc@plt>
jmp    1215 <main+0xa5>
mov    -0x2c(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <putc@plt>
jmp    11bd <main+0x4d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe82(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe76(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e36(%rip),%r15
cmp    (%r15),%eax
jne    11d4 <main+0x64>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
jmp    11fe <main+0x8e>
nopl   0x0(%rax,%rax,1)
call   1030 <toupper@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     11b7 <main+0x47>
mov    %ebp,%edi
call   1080 <isupper@plt>
mov    %ebp,%edi
test   %rax,%rax
je     11e0 <main+0x70>
call   1070 <tolower@plt>
jmp    11e5 <main+0x75>

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

LLVM IR (-O2):
@.str = [10 x i8] c"goods.txt\00"
@.str.1 = [11 x i8] c"goods2.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32 @fgetc(i32* %1)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %20, label %6
6: ; preds = %0, %14
%7 = phi i32 [ %17, %14 ], [ %3, %0 ]
%8 = tail call i64 @isupper(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @tolower(i32 %7)
br label %14
12: ; preds = %6
%13 = tail call i32 @toupper(i32 %7)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %13, %12 ], [ %11, %10 ]
%16 = tail call i32 @putc(i32 %15, i32* %2)
%17 = tail call i32 @fgetc(i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %6
20: ; preds = %14, %0
%21 = tail call i32 @fclose(i32* %1)
%22 = tail call i32 @fclose(i32* %2)
ret i32 0
}