#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*/ perror(char *);
int /*<<< orphan*/ *stdout;
int main(void) {
  FILE *fp;
  int i;
  fp = fopen("test.txt", "w");
  if (fp == NULL) {
    perror("test.txt");
    return -1;
  }
  for (i = 0; i < 5; i++) {
    fputc('A' + i, fp);
  }
  for (i = 0; i < 5; i++) {
    fputc('A' + i, stdout);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <main+0x49>
lea    0xe88(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <main+0xc1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11ba <main+0x7a>
mov    -0x14(%rbp),%eax
add    $0x41,%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <main+0x50>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11f1 <main+0xb1>
mov    -0x14(%rbp),%eax
add    $0x41,%eax
mov    0x2e08(%rip),%rcx
mov    (%rcx),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <main+0x81>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11fe <main+0xbe>
mov    %rax,%rbx
mov    $0x41,%edi
mov    %rax,%rsi
call   1040 <fputc@plt>
mov    $0x42,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    $0x43,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    $0x44,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    $0x45,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x2e35(%rip),%r14
mov    (%r14),%rsi
mov    $0x41,%edi
call   1040 <fputc@plt>
mov    (%r14),%rsi
mov    $0x42,%edi
call   1040 <fputc@plt>
mov    (%r14),%rsi
mov    $0x43,%edi
call   1040 <fputc@plt>
mov    (%r14),%rsi
mov    $0x44,%edi
call   1040 <fputc@plt>
mov    (%r14),%rsi
mov    $0x45,%edi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdfb(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11f6 <main+0xb6>

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

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32* null
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %20, 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 = load i32*, i32** @stdout
%10 = tail call i32 @fputc(i8 signext 65, i32* %9)
%11 = load i32*, i32** @stdout
%12 = tail call i32 @fputc(i8 signext 66, i32* %11)
%13 = load i32*, i32** @stdout
%14 = tail call i32 @fputc(i8 signext 67, i32* %13)
%15 = load i32*, i32** @stdout
%16 = tail call i32 @fputc(i8 signext 68, i32* %15)
%17 = load i32*, i32** @stdout
%18 = tail call i32 @fputc(i8 signext 69, i32* %17)
%19 = tail call i32 @fclose(i32* %1)
br label %22
20: ; preds = %0
%21 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %3, %20
%23 = phi i32 [ -1, %20 ], [ 0, %3 ]
ret i32 %23
}