#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fidopen(int, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ toupper(char);
int Capitalize(size_t argc, const char **argv) {
  char c;
  FILE *fin = fidopen(0, "r");
  FILE *fout = fidopen(1, "w");
  while ((c = fgetc(fin)) != EOF) {
    fputc(toupper(c), fout);
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<Capitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    0xe97(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e4b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c1 <Capitalize+0x71>
movsbl -0x11(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    1187 <Capitalize+0x37>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Capitalize>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rsi
xor    %edi,%edi
call   1070 <fidopen@plt>
mov    %rax,%r14
lea    0xe95(%rip),%rsi
mov    $0x1,%edi
call   1070 <fidopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e5f(%rip),%r15
cmp    (%r15),%al
je     11af <Capitalize+0x5f>
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    1190 <Capitalize+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @Capitalize(i64 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i32*
store i64 %0, i64* %3
store i8** %1, i8*** %4
%8 = call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
br label %10
10: ; preds = %17, %2
%11 = load i32*, i32** %6
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %5
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i8, i8* %5
%19 = call i32 @toupper(i8 signext %18)
%20 = load i32*, i32** %7
%21 = call i32 @fputc(i32 %19, i32* %20)
br label %10
22: ; preds = %10
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = load i32*, i32** %7
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @Capitalize(i64 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fidopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call signext i8 @fgetc(i32* %3)
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %12, %8 ], [ %5, %2 ]
%10 = tail call i32 @toupper(i8 signext %9)
%11 = tail call i32 @fputc(i32 %10, i32* %4)
%12 = tail call signext i8 @fgetc(i32* %3)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %8
15: ; preds = %8, %2
%16 = tail call i32 @fclose(i32* %3)
%17 = tail call i32 @fclose(i32* %4)
ret i32 0
}