#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fwrite(char *, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int rc = 0;
  const char *result;
  const char *filename = "./file.test";
  printf("  Creating %s.\n", filename);
  printf("    fopen(): ");
  FILE *fp = fopen(filename, "w");
  rc = (fp != 0) ? 0 : 1;
  result = (rc == 0) ? "PASS" : "FAIL";
  printf("%s.\n", result);
  if (rc == 0) {
    int count;
    for (count = 0; count < 1024; count++) {
      char buf[64];
      snprintf(buf, sizeof(buf), "%06d: %06d\n", count, count);
      printf("    fwrite(): %6d: ", count);
      if (fwrite(buf, strlen(buf), 1, fp) != 1) {
        rc = 1;
      }
      result = (rc == 0) ? "PASS" : "FAIL";
      printf("%s.\n", result);
    }
  }
  if (fp != (FILE *)0) {
    printf("    fclose(): ");
    rc = fclose(fp);
    result = (rc == 0) ? "PASS" : "FAIL";
    printf("%s.\n", result);
  }
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    0xe53(%rip),%rax
lea    0xe47(%rip),%rcx
cmp    $0x0,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12c9 <main+0x169>
movl   $0x0,-0x34(%rbp)
cmpl   $0x400,-0x34(%rbp)
jge    12c4 <main+0x164>
lea    -0x80(%rbp),%rdi
mov    -0x34(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    $0x40,%esi
lea    0xdff(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x34(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     1288 <main+0x128>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    0xd9f(%rip),%rax
lea    0xd93(%rip),%rcx
cmp    $0x0,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1213 <main+0xb3>
jmp    12c9 <main+0x169>
cmpq   $0x0,-0x30(%rbp)
je     131c <main+0x1bc>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    0xd39(%rip),%rax
lea    0xd2d(%rip),%rcx
cmp    $0x0,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe97(%rip),%rdi
lea    0xe84(%rip),%rbp
xor    %ebx,%ebx
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8d(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
lea    0xe7f(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14,%r14
je     12a0 <main+0x140>
mov    %rsp,%r12
lea    0xe64(%rip),%r13
lea    0xe32(%rip),%rbp
xor    %r15d,%r15d
jmp    1205 <main+0xa5>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    $0x400,%ebx
je     1264 <main+0x104>
mov    %r12,%rdi
mov    $0x40,%esi
lea    0xe22(%rip),%rdx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1060 <snprintf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     124f <main+0xef>
mov    $0x1,%r15d
lea    0xdd6(%rip),%rsi
test   %r15d,%r15d
je     11f0 <main+0x90>
lea    0xdcf(%rip),%rsi
jmp    11f0 <main+0x90>
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %eax,%ebx
test   %eax,%eax
lea    0xda7(%rip),%rax
lea    0xda5(%rip),%rsi
cmove  %rax,%rsi
lea    0xd80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12a5 <main+0x145>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./file.test\00"
@.str.1 = [16 x i8] c" Creating %s.\0A\00"
@.str.2 = [14 x i8] c" fopen(): \00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [5 x i8] c"PASS\00"
@.str.5 = [5 x i8] c"FAIL\00"
@.str.6 = [5 x i8] c"%s.\0A\00"
@.str.7 = [12 x i8] c"%06d: %06d\0A\00"
@.str.8 = [20 x i8] c" fwrite(): %6d: \00"
@.str.9 = [15 x i8] c" fclose(): \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = load i8*, i8** %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %8
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = icmp ne i32* %17, null
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 0, i32 1
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %58
29: ; preds = %2
store i32 0, i32* %10
br label %30
30: ; preds = %54, %29
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 1024
br i1 %32, label %33, label %57
33: ; preds = %30
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%35 = load i32, i32* %10
%36 = load i32, i32* %10
%37 = call i32 @snprintf(i8* %34, i32 64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32, i32* %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = load i32*, i32** %9
%44 = call i32 @fwrite(i8* %40, i32 %42, i32 1, i32* %43)
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %47
46: ; preds = %33
store i32 1, i32* %6
br label %47
47: ; preds = %46, %33
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i64
%51 = select i1 %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %47
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %30
57: ; preds = %30
br label %58
58: ; preds = %57, %2
%59 = load i32*, i32** %9
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %71
61: ; preds = %58
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%63 = load i32*, i32** %9
%64 = call i32 @fclose(i32* %63)
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 0
%67 = zext i1 %66 to i64
%68 = select i1 %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
store i8* %68, i8** %7
%69 = load i8*, i8** %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %61, %58
%72 = load i32, i32* %6
ret i32 %72
}

LLVM IR (-O2):
@.str = [12 x i8] c"./file.test\00"
@.str.1 = [16 x i8] c" Creating %s.\0A\00"
@.str.2 = [14 x i8] c" fopen(): \00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [5 x i8] c"PASS\00"
@.str.5 = [5 x i8] c"FAIL\00"
@.str.6 = [5 x i8] c"%s.\0A\00"
@.str.7 = [12 x i8] c"%06d: %06d\0A\00"
@.str.8 = [20 x i8] c" fwrite(): %6d: \00"
@.str.9 = [15 x i8] c" fclose(): \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%6 = 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.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
%8 = select i1 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br i1 %7, label %32, label %10
10: ; preds = %2
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 0, %10 ], [ %24, %12 ]
%14 = phi i32 [ 0, %10 ], [ %20, %12 ]
%15 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %13, i32 %13)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %13)
%17 = call i32 @strlen(i8* %11)
%18 = call i32 @fwrite(i8* %11, i32 %17, i32 1, i32* %6)
%19 = icmp eq i32 %18, 1
%20 = select i1 %19, i32 %14, i32 1
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %22)
%24 = add nuw nsw i32 %13, 1
%25 = icmp eq i32 %24, 1024
br i1 %25, label %26, label %12
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%28 = call i32 @fclose(i32* %6)
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %2, %26
%33 = phi i32 [ %28, %26 ], [ 1, %2 ]
ret i32 %33
}