#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
void main() {
  long bulbs;
  int i;
  int state = 0;
  printf("Problem 6: How many bulbs (0 < n <1 000 000 000) are present, Mr. "
         "Mabu?");
  scanf("%ld", &bulbs);
  for (i = 2; i <= bulbs; i++) {
    if (bulbs % i == 0) {
      if (state) {
        state = 0;
      } else {
        state = 1;
      }
    }
  }
  if (state) {
    printf("Bulb %d is on.", bulbs);
  } else {
    printf("Blub %d is off.", bulbs);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x2,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     11ae <main+0x8e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    119b <main+0x7b>
cmpl   $0x0,-0x10(%rbp)
je     118f <main+0x6f>
movl   $0x0,-0x10(%rbp)
jmp    1196 <main+0x76>
movl   $0x1,-0x10(%rbp)
jmp    119b <main+0x7b>
jmp    11a0 <main+0x80>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <main+0x34>
cmpl   $0x0,-0x10(%rbp)
je     11cf <main+0xaf>
mov    -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e1 <main+0xc1>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%r10
cmp    $0x2,%r10
jl     124e <main+0x12e>
lea    -0x1(%r10),%r8
cmp    $0x2,%r10
jne    1182 <main+0x62>
mov    $0x2,%edi
test   $0x1,%r8b
jne    121c <main+0xfc>
test   %ebx,%ebx
je     124e <main+0x12e>
lea    0xecf(%rip),%rdi
jmp    1255 <main+0x135>
mov    %r8,%r9
and    $0xfffffffffffffffe,%r9
xor    %ebx,%ebx
mov    $0x2,%ecx
jmp    11c2 <main+0xa2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r10,%rax
cqto
idiv   %rcx
xor    %ebx,%ebx
test   %esi,%esi
sete   %bl
test   %rdx,%rdx
cmovne %esi,%ebx
lea    -0x1(%rcx),%rax
add    $0x1,%rcx
cmp    %r9,%rax
je     120e <main+0xee>
mov    %rcx,%rdi
mov    %r10,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11e0 <main+0xc0>
mov    %r10,%rax
cqto
idiv   %rdi
jmp    11e7 <main+0xc7>
nopl   0x0(%rax,%rax,1)
mov    %r10d,%eax
xor    %edx,%edx
div    %edi
xor    %esi,%esi
test   %ebx,%ebx
sete   %sil
test   %rdx,%rdx
cmovne %ebx,%esi
lea    0x1(%rdi),%rcx
mov    %r10,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    11a0 <main+0x80>
mov    %r10d,%eax
xor    %edx,%edx
div    %ecx
jmp    11a8 <main+0x88>
add    $0x2,%rdi
test   $0x1,%r8b
je     116e <main+0x4e>
mov    %r10,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1232 <main+0x112>
mov    %r10,%rax
cqto
idiv   %rdi
jmp    1239 <main+0x119>
mov    %r10d,%eax
xor    %edx,%edx
div    %edi
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
test   %rdx,%rdx
cmove  %eax,%ebx
test   %ebx,%ebx
jne    1176 <main+0x56>
lea    0xe06(%rip),%rdi
mov    %r10,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [72 x i8] c"Problem 6: How many bulbs (0 < n <1 000 000 000) are present, Mr. Mabu?\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [15 x i8] c"Bulb %d is on.\00"
@.str.3 = [16 x i8] c"Blub %d is off.\00"
define void @main() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
store i32 2, i32* %2
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = load i64, i64* %1
%10 = icmp sle i64 %8, %9
br i1 %10, label %11, label %27
11: ; preds = %6
%12 = load i64, i64* %1
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = srem i64 %12, %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %3
br label %22
21: ; preds = %17
store i32 1, i32* %3
br label %22
22: ; preds = %21, %20
br label %23
23: ; preds = %22, %11
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %6
27: ; preds = %6
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i64, i64* %1
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %31)
br label %36
33: ; preds = %27
%34 = load i64, i64* %1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %34)
br label %36
36: ; preds = %33, %30
ret void
}

LLVM IR (-O2):
@.str = [72 x i8] c"Problem 6: How many bulbs (0 < n <1 000 000 000) are present, Mr. Mabu?\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [15 x i8] c"Bulb %d is on.\00"
@.str.3 = [16 x i8] c"Blub %d is off.\00"
define void @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = icmp slt i64 %5, 2
br i1 %6, label %45, label %7
7: ; preds = %0
%8 = add i64 %5, -1
%9 = and i64 %8, 1
%10 = icmp eq i64 %5, 2
br i1 %10, label %31, label %11
11: ; preds = %7
%12 = and i64 %8, -2
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 2, %11 ], [ %28, %13 ]
%15 = phi i32 [ 0, %11 ], [ %27, %13 ]
%16 = phi i64 [ 0, %11 ], [ %29, %13 ]
%17 = srem i64 %5, %14
%18 = icmp eq i64 %17, 0
%19 = icmp eq i32 %15, 0
%20 = zext i1 %19 to i32
%21 = select i1 %18, i32 %20, i32 %15
%22 = or i64 %14, 1
%23 = srem i64 %5, %22
%24 = icmp eq i64 %23, 0
%25 = icmp eq i32 %21, 0
%26 = zext i1 %25 to i32
%27 = select i1 %24, i32 %26, i32 %21
%28 = add nuw nsw i64 %14, 2
%29 = add i64 %16, 2
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %13
31: ; preds = %13, %7
%32 = phi i32 [ undef, %7 ], [ %27, %13 ]
%33 = phi i64 [ 2, %7 ], [ %28, %13 ]
%34 = phi i32 [ 0, %7 ], [ %27, %13 ]
%35 = icmp eq i64 %9, 0
br i1 %35, label %42, label %36
36: ; preds = %31
%37 = srem i64 %5, %33
%38 = icmp eq i64 %37, 0
%39 = icmp eq i32 %34, 0
%40 = zext i1 %39 to i32
%41 = select i1 %38, i32 %40, i32 %34
br label %42
42: ; preds = %31, %36
%43 = phi i32 [ %32, %31 ], [ %41, %36 ]
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %0, %42
br label %46
46: ; preds = %42, %45
%47 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %45 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %42 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %47, i64 %5)
ret void
}