#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, unsigned long);
int main() {
  char *check;
  unsigned long i, j;
  int count;
  check = (char *)malloc(1 << 30 * sizeof(char));
  i = 1;
  check[1] = 1;
  count = 1;
  while (count < 1500) {
    i++;
    if (!(i % 2))
      check[i] = check[i / 2];
    else if (!(i % 3))
      check[i] = check[i / 3];
    else if (!(i % 5))
      check[i] = check[i / 5];
    else
      check[i] = 0;
    count += check[i];
  }
  printf("The %d'th ugly number is %d.\n", 1500, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x40000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x1,0x1(%rax)
movl   $0x1,-0x24(%rbp)
cmpl   $0x5dc,-0x24(%rbp)
jge    125b <main+0x13b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    119e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    $0x1,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1244 <main+0x124>
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    11e6 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123f <main+0x11f>
mov    -0x18(%rbp),%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    122e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    123f <main+0x11f>
jmp    1244 <main+0x124>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <main+0x34>
mov    -0x18(%rbp),%rdx
lea    0xd9a(%rip),%rdi
mov    $0x5dc,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x40000000,%edi
call   1040 <malloc@plt>
mov    %rax,%r8
movb   $0x1,0x1(%rax)
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x2,%esi
movabs $0xcccccccccccccccd,%r10
cc cc cc
movabs $0xaaaaaaaaaaaaaaab,%r11
aa aa aa
jmp    1184 <main+0x64>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdx
shr    %rdx
movzbl (%r8,%rdx,1),%eax
mov    %al,0x1(%r8,%rbx,1)
movsbl %al,%eax
add    %eax,%edi
add    $0x1,%rsi
mov    %r14,%rbx
cmp    $0x5dc,%edi
jge    11e4 <main+0xc4>
mov    %rsi,%rax
mul    %r10
mov    %rdx,%r9
lea    0x1(%rbx),%r14
mov    %rsi,%rax
mul    %r11
test   $0x1,%r14b
je     1160 <main+0x40>
shr    %rdx
lea    (%rdx,%rdx,2),%rax
mov    $0x2,%ecx
sub    %rax,%rcx
add    %rbx,%rcx
mov    %r14,%rax
mul    %r11
cmp    $0x1,%rcx
je     1163 <main+0x43>
shr    $0x2,%r9
lea    (%r9,%r9,4),%rax
mov    $0x2,%ecx
sub    %rax,%rcx
add    %rbx,%rcx
mov    %r14,%rax
mul    %r10
cmp    $0x1,%rcx
jne    11e0 <main+0xc0>
shr    $0x2,%rdx
jmp    1166 <main+0x46>
xor    %eax,%eax
jmp    116b <main+0x4b>
lea    0xe15(%rip),%rdi
mov    $0x5dc,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"The %d'th ugly number is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 @malloc(i32 1073741824)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
store i64 1, i64* %3
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 1, i8* %9
store i32 1, i32* %5
br label %10
10: ; preds = %60, %0
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 1500
br i1 %12, label %13, label %68
13: ; preds = %10
%14 = load i64, i64* %3
%15 = add i64 %14, 1
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = urem i64 %16, 2
%18 = icmp ne i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %13
%20 = load i8*, i8** %2
%21 = load i64, i64* %3
%22 = udiv i64 %21, 2
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 %24, i8* %27
br label %60
28: ; preds = %13
%29 = load i64, i64* %3
%30 = urem i64 %29, 3
%31 = icmp ne i64 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %28
%33 = load i8*, i8** %2
%34 = load i64, i64* %3
%35 = udiv i64 %34, 3
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %2
%39 = load i64, i64* %3
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
br label %59
41: ; preds = %28
%42 = load i64, i64* %3
%43 = urem i64 %42, 5
%44 = icmp ne i64 %43, 0
br i1 %44, label %54, label %45
45: ; preds = %41
%46 = load i8*, i8** %2
%47 = load i64, i64* %3
%48 = udiv i64 %47, 5
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %2
%52 = load i64, i64* %3
%53 = getelementptr inbounds i8, i8* %51, i64 %52
store i8 %50, i8* %53
br label %58
54: ; preds = %41
%55 = load i8*, i8** %2
%56 = load i64, i64* %3
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8 0, i8* %57
br label %58
58: ; preds = %54, %45
br label %59
59: ; preds = %58, %32
br label %60
60: ; preds = %59, %19
%61 = load i8*, i8** %2
%62 = load i64, i64* %3
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = load i32, i32* %5
%67 = add nsw i32 %66, %65
store i32 %67, i32* %5
br label %10
68: ; preds = %10
%69 = load i64, i64* %3
%70 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 1500, i64 %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"The %d'th ugly number is %d.\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 1073741824)
%2 = inttoptr i64 %1 to i8*
%3 = getelementptr inbounds i8, i8* %2, i64 1
store i8 1, i8* %3
br label %4
4: ; preds = %0, %24
%5 = phi i32 [ 1, %0 ], [ %28, %24 ]
%6 = phi i64 [ 1, %0 ], [ %7, %24 ]
%7 = add i64 %6, 1
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = lshr i64 %7, 1
br label %20
12: ; preds = %4
%13 = urem i64 %7, 3
%14 = udiv i64 %7, 3
%15 = icmp eq i64 %13, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = urem i64 %7, 5
%18 = udiv i64 %7, 5
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %16, %12, %10
%21 = phi i64 [ %11, %10 ], [ %14, %12 ], [ %18, %16 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %21
%23 = load i8, i8* %22
br label %24
24: ; preds = %20, %16
%25 = phi i8 [ 0, %16 ], [ %23, %20 ]
%26 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 %25, i8* %26
%27 = sext i8 %25 to i32
%28 = add nsw i32 %5, %27
%29 = icmp slt i32 %28, 1500
br i1 %29, label %4, label %30
30: ; preds = %24
%31 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 1500, i64 %7)
ret i32 0
}