#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*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, int);
int main() {
  int x, y, z;
  int val = 0;
  FILE *file = fopen("tomo.tab", "wt");
  for (x = 0; x < 256; x++) {
    for (y = 0; y < 256; y++) {
      for (z = 0; z < 154; z++) {
        val = (val + 1) & 0xFF;
        fprintf(file, "%4d,%4d,%4d,%4d\n", x, y, z, val);
      }
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    11f9 <main+0xc9>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    11e6 <main+0xb6>
movl   $0x0,-0x10(%rbp)
cmpl   $0x9a,-0x10(%rbp)
jge    11d3 <main+0xa3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <main+0x5c>
jmp    11d8 <main+0xa8>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <main+0x48>
jmp    11eb <main+0xbb>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1164 <main+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
xor    %r12d,%r12d
lea    0xeb1(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
movzbl %bl,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %ebp,%r8d
mov    %ebx,%r9d
call   1040 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x9a,%ebp
jne    1180 <main+0x50>
add    $0x1,%r13d
cmp    $0x100,%r13d
jne    1170 <main+0x40>
add    $0x1,%r12d
cmp    $0x100,%r12d
jne    1160 <main+0x30>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"tomo.tab\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [17 x i8] c"%4d,%4d,%4d,%4d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
store i32 0, i32* %2
br label %8
8: ; preds = %37, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %40
11: ; preds = %8
store i32 0, i32* %3
br label %12
12: ; preds = %33, %11
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 256
br i1 %14, label %15, label %36
15: ; preds = %12
store i32 0, i32* %4
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 154
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = and i32 %21, 255
store i32 %22, i32* %5
%23 = load i32*, i32** %6
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25, i32 %26, i32 %27)
br label %29
29: ; preds = %19
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %16
32: ; preds = %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %12
36: ; preds = %12
br label %37
37: ; preds = %36
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %8
40: ; preds = %8
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"tomo.tab\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [17 x i8] c"%4d,%4d,%4d,%4d\0A\00"
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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %19
%3 = phi i32 [ 0, %0 ], [ %20, %19 ]
%4 = phi i32 [ 0, %0 ], [ %12, %19 ]
br label %5
5: ; preds = %2, %16
%6 = phi i32 [ %4, %2 ], [ %12, %16 ]
%7 = phi i32 [ 0, %2 ], [ %17, %16 ]
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ %6, %5 ], [ %12, %8 ]
%10 = phi i32 [ 0, %5 ], [ %14, %8 ]
%11 = add nuw nsw i32 %9, 1
%12 = and i32 %11, 255
%13 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %7, i32 %10, i32 %12)
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, 154
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = add nuw nsw i32 %7, 1
%18 = icmp eq i32 %17, 256
br i1 %18, label %19, label %5
19: ; preds = %16
%20 = add nuw nsw i32 %3, 1
%21 = icmp eq i32 %20, 256
br i1 %21, label %22, label %2
22: ; preds = %19
%23 = tail call i32 @fclose(i32* %1)
ret i32 0
}