#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *filename = "allcaps.txt";
  FILE *fp = fopen(filename, "w");
  char c = 'A';
  if (fp) {
    while (c <= 'Z') {
      fputc(c, fp);
      c++;
    }
    fputc('\n', fp);
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x41,-0x19(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c7 <main+0x87>
jmp    1182 <main+0x42>
movsbl -0x19(%rbp),%eax
cmp    $0x5a,%eax
jg     11ab <main+0x6b>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1182 <main+0x42>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d7 <main+0x97>
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12c9 <main+0x189>
mov    %rax,%rbx
mov    $0x41,%edi
mov    %rax,%rsi
call   1050 <fputc@plt>
mov    $0x42,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x43,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x44,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x45,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x46,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x47,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x48,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x49,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4a,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4b,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4c,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4e,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x4f,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x50,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x51,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x52,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x53,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x54,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x55,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x56,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x57,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x58,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x59,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x5a,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    12dc <main+0x19c>
lea    0xd3e(%rip),%rdi
lea    0xd29(%rip),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"allcaps.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
store i8 65, i8* %4
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %25
9: ; preds = %0
br label %10
10: ; preds = %14, %9
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp sle i32 %12, 90
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8, i8* %4
%16 = load i32*, i32** %3
%17 = call i32 @fputc(i8 signext %15, i32* %16)
%18 = load i8, i8* %4
%19 = add i8 %18, 1
store i8 %19, i8* %4
br label %10
20: ; preds = %10
%21 = load i32*, i32** %3
%22 = call i32 @fputc(i8 signext 10, i32* %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
br label %28
25: ; preds = %0
%26 = load i8*, i8** %2
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"allcaps.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %32, label %3
3: ; preds = %0
%4 = tail call i32 @fputc(i8 signext 65, i32* %1)
%5 = tail call i32 @fputc(i8 signext 66, i32* %1)
%6 = tail call i32 @fputc(i8 signext 67, i32* %1)
%7 = tail call i32 @fputc(i8 signext 68, i32* %1)
%8 = tail call i32 @fputc(i8 signext 69, i32* %1)
%9 = tail call i32 @fputc(i8 signext 70, i32* %1)
%10 = tail call i32 @fputc(i8 signext 71, i32* %1)
%11 = tail call i32 @fputc(i8 signext 72, i32* %1)
%12 = tail call i32 @fputc(i8 signext 73, i32* %1)
%13 = tail call i32 @fputc(i8 signext 74, i32* %1)
%14 = tail call i32 @fputc(i8 signext 75, i32* %1)
%15 = tail call i32 @fputc(i8 signext 76, i32* %1)
%16 = tail call i32 @fputc(i8 signext 77, i32* %1)
%17 = tail call i32 @fputc(i8 signext 78, i32* %1)
%18 = tail call i32 @fputc(i8 signext 79, i32* %1)
%19 = tail call i32 @fputc(i8 signext 80, i32* %1)
%20 = tail call i32 @fputc(i8 signext 81, i32* %1)
%21 = tail call i32 @fputc(i8 signext 82, i32* %1)
%22 = tail call i32 @fputc(i8 signext 83, i32* %1)
%23 = tail call i32 @fputc(i8 signext 84, i32* %1)
%24 = tail call i32 @fputc(i8 signext 85, i32* %1)
%25 = tail call i32 @fputc(i8 signext 86, i32* %1)
%26 = tail call i32 @fputc(i8 signext 87, i32* %1)
%27 = tail call i32 @fputc(i8 signext 88, i32* %1)
%28 = tail call i32 @fputc(i8 signext 89, i32* %1)
%29 = tail call i32 @fputc(i8 signext 90, i32* %1)
%30 = tail call i32 @fputc(i8 signext 10, i32* %1)
%31 = tail call i32 @fclose(i32* %1)
br label %34
32: ; preds = %0
%33 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %3
ret i32 0
}