#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ processTwoRays(int, int, int, int, int);
int /*<<< orphan*/ stdout;
void *doWork(const int *const firstLine) {
  int i, j, k = 0;
  assert(*firstLine >= 0);
  for (j = *firstLine; j < 512 / 2; j += 4)
    for (i = 0; i < 512 / 2; i += 2) {
      processTwoRays(i, j, i + 1, j, 4);
      if (*firstLine == 0) {
        printf("[%3d%%]\r",
               (int)(100.0 * 4.0 * 4 * ((double)k) / ((double)(512 * 512))));
        fflush(stdout);
      }
      k += 2;
    }
  if (*firstLine == 0)
    printf("[100%%]\n");
  return (NULL);
}


x86 assembly (clang, -O0):
<doWork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    121f <doWork+0xdf>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    120c <doWork+0xcc>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
mov    $0x4,%r8d
call   1040 <processTwoRays@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11f5 <doWork+0xb5>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe43(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe2f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <doWork+0x44>
jmp    1211 <doWork+0xd1>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1170 <doWork+0x30>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    123a <doWork+0xfa>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doWork>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
mov    (%r14),%r12d
cmp    $0xff,%r12d
jg     121b <doWork+0xdb>
mov    0x2e6f(%rip),%rbp
xor    %r15d,%r15d
jmp    1198 <doWork+0x58>
cs nopw 0x0(%rax,%rax,1)
add    $0x2,%r13d
lea    0x4(%r12),%eax
add    %r13d,%r15d
cmp    $0xfc,%r12d
mov    %eax,%r12d
jge    1207 <doWork+0xc7>
xor    %ebx,%ebx
jmp    11ad <doWork+0x6d>
nopl   0x0(%rax)
lea    -0x1(%rbx),%eax
add    $0x1,%ebx
cmp    $0xfe,%eax
jae    1180 <doWork+0x40>
mov    %ebx,%r13d
lea    0x1(%r13),%ebx
mov    %r13d,%edi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    $0x4,%r8d
call   1040 <processTwoRays@plt>
cmpl   $0x0,(%r14)
jne    11a0 <doWork+0x60>
lea    (%r15,%r13,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe1d(%rip),%xmm0
mulsd  0xe1d(%rip),%xmm0
cvttsd2si %xmm0,%esi
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp),%edi
call   1060 <fflush@plt>
jmp    11a0 <doWork+0x60>
cmpl   $0x0,(%r14)
jne    121b <doWork+0xdb>
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@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"[%3d%%]\0D\00"
@stdout = global i32 0
@.str.1 = [9 x i8] c"[100%%]\0A\00"
define i8* @doWork(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
%6 = load i32*, i32** %2
%7 = load i32, i32* %6
%8 = icmp sge i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32*, i32** %2
%12 = load i32, i32* %11
store i32 %12, i32* %4
br label %13
13: ; preds = %46, %1
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 256
br i1 %15, label %16, label %49
16: ; preds = %13
store i32 0, i32* %3
br label %17
17: ; preds = %42, %16
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 256
br i1 %19, label %20, label %45
20: ; preds = %17
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %4
%26 = call i32 @processTwoRays(i32 %21, i32 %22, i32 %24, i32 %25, i32 4)
%27 = load i32*, i32** %2
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %20
%31 = load i32, i32* %5
%32 = sitofp i32 %31 to double
%33 = fmul double 1.600000e+03, %32
%34 = fdiv double %33, 2.621440e+05
%35 = fptosi double %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
br label %39
39: ; preds = %30, %20
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 2
store i32 %41, i32* %5
br label %42
42: ; preds = %39
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 2
store i32 %44, i32* %3
br label %17
45: ; preds = %17
br label %46
46: ; preds = %45
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 4
store i32 %48, i32* %4
br label %13
49: ; preds = %13
%50 = load i32*, i32** %2
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
ret i8* null
}

LLVM IR (-O2):
@.str = [9 x i8] c"[%3d%%]\0D\00"
@stdout = global i32 0
@.str.1 = [9 x i8] c"[100%%]\0A\00"
define noalias i8* @doWork(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = xor i32 %2, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = load i32, i32* %0
%7 = icmp slt i32 %6, 256
br i1 %7, label %8, label %38
8: ; preds = %1, %30
%9 = phi i32 [ %27, %30 ], [ 0, %1 ]
%10 = phi i32 [ %31, %30 ], [ %6, %1 ]
br label %11
11: ; preds = %8, %26
%12 = phi i32 [ %9, %8 ], [ %27, %26 ]
%13 = phi i32 [ 0, %8 ], [ %28, %26 ]
%14 = or i32 %13, 1
%15 = tail call i32 @processTwoRays(i32 %13, i32 %10, i32 %14, i32 %10, i32 4)
%16 = load i32, i32* %0
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = sitofp i32 %12 to double
%20 = fmul double %19, 1.600000e+03
%21 = fmul double %20, 0x3ED0000000000000
%22 = fptosi double %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
br label %26
26: ; preds = %18, %11
%27 = add nsw i32 %12, 2
%28 = add nuw nsw i32 %13, 2
%29 = icmp ult i32 %13, 254
br i1 %29, label %11, label %30
30: ; preds = %26
%31 = add nsw i32 %10, 4
%32 = icmp slt i32 %10, 252
br i1 %32, label %8, label %33
33: ; preds = %30
%34 = load i32, i32* %0
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %1, %36, %33
ret i8* null
}