#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*/ *fopen(char *, char *);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void main(void) {
  FILE *fp;
  if ((fp = fopen("QCRYPT.TST", "w")) == NULL) {
    printf("couldn't not open qcrypt.tst for writing\n");
    return;
  }
  int len = 512;
  int vals[512] = {0, 1, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < len; ++i) {
    if (fwrite(&vals[i], 1, 1, fp) != 1) {
      printf("didn't write 1 object to qcrypt.tst\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    117d <main+0x3d>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    120d <main+0xcd>
movl   $0x200,-0xc(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
movl   $0x1,-0x80c(%rbp)
movl   $0x0,-0x814(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120d <main+0xcd>
movslq -0x814(%rbp),%rax
lea    -0x810(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     11f4 <main+0xb4>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11f9 <main+0xb9>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    11ab <main+0x6b>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
lea    0xead(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cf <main+0x8f>
mov    %rax,%r15
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x800,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x1,0x4(%rsp)
lea    0xe86(%rip),%r14
jmp    119d <main+0x5d>
nopl   0x0(%rax)
add    $0x4,%rbx
cmp    $0x800,%rbx
je     11c2 <main+0x82>
lea    (%rsp,%rbx,1),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     1190 <main+0x50>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x50>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5b(%rip),%rdi
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"QCRYPT.TST\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [42 x i8] c"couldn't not open qcrypt.tst for writing\0A\00"
@.str.3 = [37 x i8] c"didn't write 1 object to qcrypt.tst\0A\00"
define void @main() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [512 x i32]
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %30
9: ; preds = %0
store i32 512, i32* %2
%10 = bitcast [512 x i32]* %3 to i8*
%11 = bitcast i8* %10 to <{ i32, i32, [510 x i32] }>*
%12 = getelementptr inbounds <{ i32, i32, [510 x i32] }>, <{ i32, i32, [510 x i32] }>* %11, i32 0, i32 1
store i32 1, i32* %12
store i32 0, i32* %4
br label %13
13: ; preds = %27, %9
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 %19
%21 = load i32*, i32** %1
%22 = call i32 @fwrite(i32* %20, i32 1, i32 1, i32* %21)
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %13
30: ; preds = %7, %13
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"QCRYPT.TST\00"
@.str.1 = [2 x i8] c"w\00"
@str = [36 x i8] c"didn't write 1 object to qcrypt.tst\00"
@str.4 = [41 x i8] c"couldn't not open qcrypt.tst for writing\00"
define void @main() {
%1 = alloca [512 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.4, i64 0, i64 0))
br label %20
6: ; preds = %0
%7 = bitcast [512 x i32]* %1 to i8*
%8 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 1
store i32 1, i32* %8
br label %10
9: ; preds = %17
br label %20
10: ; preds = %6, %17
%11 = phi i64 [ 0, %6 ], [ %18, %17 ]
%12 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 %11
%13 = call i32 @fwrite(i32* %12, i32 1, i32 1, i32* %2)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %10, %15
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, 512
br i1 %19, label %9, label %10
20: ; preds = %9, %4
ret void
}