#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*/ isUglyNumber(long);
long calcUglyNumber(int nth) {
  long number = 1;
  int n = 1;
  if (nth == 1)
    return 1;
  while (++number) {
    if (!isUglyNumber(number))
      continue;
    n++;
    if (n == nth)
      return number;
  }
}


x86 assembly (clang, -O0):
<calcUglyNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1141 <calcUglyNumber+0x31>
movq   $0x1,-0x8(%rbp)
jmp    119a <calcUglyNumber+0x8a>
jmp    1146 <calcUglyNumber+0x36>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119a <calcUglyNumber+0x8a>
mov    -0x18(%rbp),%rdi
call   1030 <isUglyNumber@plt>
cmp    $0x0,%eax
jne    1173 <calcUglyNumber+0x63>
jmp    1146 <calcUglyNumber+0x36>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1195 <calcUglyNumber+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <calcUglyNumber+0x8a>
jmp    1146 <calcUglyNumber+0x36>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcUglyNumber>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebx
cmp    $0x1,%edi
jne    1126 <calcUglyNumber+0x16>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%r14d
mov    $0x1,%ebp
mov    $0x1,%eax
add    $0x1,%rax
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     111e <calcUglyNumber+0xe>
mov    %rbx,%rdi
call   1030 <isUglyNumber@plt>
add    $0x1,%rbx
test   %eax,%eax
je     1140 <calcUglyNumber+0x30>
add    $0x1,%ebp
lea    -0x1(%rbx),%rax
cmp    %r14d,%ebp
jne    1133 <calcUglyNumber+0x23>
add    $0xffffffffffffffff,%rbx
jmp    111e <calcUglyNumber+0xe>

LLVM IR (-O0):
define i64 @calcUglyNumber(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %3
store i64 1, i64* %4
store i32 1, i32* %5
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 1, i64* %2
br label %28
9: ; preds = %1
br label %10
10: ; preds = %27, %18, %9
%11 = load i64, i64* %4
%12 = add nsw i64 %11, 1
store i64 %12, i64* %4
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i64, i64* %4
%16 = call i32 @isUglyNumber(i64 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
br label %10
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i64, i64* %4
store i64 %26, i64* %2
br label %28
27: ; preds = %19
br label %10
28: ; preds = %8, %25, %10
%29 = load i64, i64* %2
ret i64 %29
}

LLVM IR (-O2):
define i64 @calcUglyNumber(i32 %0) {
%2 = icmp eq i32 %0, 1
br i1 %2, label %16, label %3
3: ; preds = %1, %13
%4 = phi i64 [ %8, %13 ], [ 1, %1 ]
%5 = phi i32 [ %14, %13 ], [ 1, %1 ]
br label %6
6: ; preds = %3, %10
%7 = phi i64 [ %8, %10 ], [ %4, %3 ]
%8 = add nsw i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = tail call i32 @isUglyNumber(i64 %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %10
%14 = add nuw nsw i32 %5, 1
%15 = icmp eq i32 %14, %0
br i1 %15, label %16, label %3
16: ; preds = %13, %6, %1
%17 = phi i64 [ 1, %1 ], [ undef, %6 ], [ %8, %13 ]
ret i64 %17
}