#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 ceil(int);
int log(int);
int /*<<< orphan*/ sieve(int *, int);
int solve(int p) {
  int n = ceil(p * log(p) + p * log(log(p)));
  bool primes[n];
  sieve(primes, n);
  int j = 0;
  int i = 0;
  while (i < p) {
    j++;
    if (primes[j]) {
      i++;
    }
  }
  return j;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,-0x34(%rbp)
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,-0x2c(%rbp)
call   1050 <log@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
call   1040 <sieve@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <solve+0xba>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11e5 <solve+0xb5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b5 <solve+0x85>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1050 <log@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1050 <log@plt>
mov    %eax,%edi
call   1050 <log@plt>
add    %eax,%ebx
imul   %r14d,%ebx
mov    %ebx,%edi
call   1030 <ceil@plt>
mov    %eax,%ecx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <sieve@plt>
xor    %eax,%eax
test   %r14d,%r14d
jle    11a1 <solve+0x71>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
cmpl   $0x1,0x4(%rbx,%rax,4)
lea    0x1(%rax),%rax
sbb    $0xffffffff,%ecx
cmp    %r14d,%ecx
jl     1190 <solve+0x60>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @solve(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @log(i32 %9)
%11 = mul nsw i32 %8, %10
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = call i32 @log(i32 %13)
%15 = call i32 @log(i32 %14)
%16 = mul nsw i32 %12, %15
%17 = add nsw i32 %11, %16
%18 = call i32 @ceil(i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %4
%22 = alloca i32, i64 %20
store i64 %20, i64* %5
%23 = load i32, i32* %3
%24 = call i32 @sieve(i32* %22, i32 %23)
store i32 0, i32* %6
store i32 0, i32* %7
br label %25
25: ; preds = %40, %1
%26 = load i32, i32* %7
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %22, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %40
40: ; preds = %37, %29
br label %25
41: ; preds = %25
%42 = load i32, i32* %6
%43 = load i8*, i8** %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @solve(i32 %0) {
%2 = tail call i32 @log(i32 %0)
%3 = tail call i32 @log(i32 %0)
%4 = tail call i32 @log(i32 %3)
%5 = add i32 %4, %2
%6 = mul i32 %5, %0
%7 = tail call i32 @ceil(i32 %6)
%8 = zext i32 %7 to i64
%9 = alloca i32, i64 %8
%10 = call i32 @sieve(i32* %9, i32 %7)
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %24
12: ; preds = %1, %12
%13 = phi i64 [ %15, %12 ], [ 0, %1 ]
%14 = phi i32 [ %20, %12 ], [ 0, %1 ]
%15 = add nuw nsw i64 %13, 1
%16 = getelementptr inbounds i32, i32* %9, i64 %15
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %14, %19
%21 = icmp slt i32 %20, %0
br i1 %21, label %12, label %22
22: ; preds = %12
%23 = trunc i64 %15 to i32
br label %24
24: ; preds = %22, %1
%25 = phi i32 [ 0, %1 ], [ %23, %22 ]
ret i32 %25
}