#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);
void *compute_prime(void *arg) {
  int candidate = 2;
  int n = *((int *)arg);
  int total_number = n;
  printf("Will compute for the %dth prime...\n", n);
  while (1) {
    int factor;
    int is_prime = 1;
    for (factor = 2; factor * factor <= candidate; factor++) {
      if (candidate % factor == 0) {
        is_prime = 0;
        break;
      }
    }
    if (is_prime) {
      if (--n == 0) {
        return (void *)candidate;
      }
    }
    ++candidate;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<compute_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     118e <compute_prime+0x7e>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    117b <compute_prime+0x6b>
movl   $0x0,-0x1c(%rbp)
jmp    118e <compute_prime+0x7e>
jmp    1180 <compute_prime+0x70>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114f <compute_prime+0x3f>
cmpl   $0x0,-0x1c(%rbp)
je     11b9 <compute_prime+0xa9>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    11b4 <compute_prime+0xa4>
movslq -0xc(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11b9 <compute_prime+0xa9>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <compute_prime+0x31>

x86 assembly (clang, -O2):
<compute_prime>:
push   %rbx
mov    (%rdi),%ebx
lea    0xee6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x2,%ecx
jmp    1138 <compute_prime+0x28>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     116b <compute_prime+0x5b>
add    $0x1,%ecx
cmp    $0x4,%ecx
jb     1130 <compute_prime+0x20>
mov    $0x3,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x1(%rsi),%edi
mov    %ecx,%eax
xor    %edx,%edx
div    %edi
test   %edx,%edx
je     1135 <compute_prime+0x25>
mov    %esi,%eax
imul   %esi,%eax
add    $0x1,%esi
cmp    %ecx,%eax
jbe    1150 <compute_prime+0x40>
jmp    1130 <compute_prime+0x20>
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Will compute for the %dth prime...\0A\00"
define i8* @compute_prime(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 2, i32* %3
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %4
%11 = load i32, i32* %4
store i32 %11, i32* %5
%12 = load i32, i32* %4
%13 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %1, %43
store i32 1, i32* %7
store i32 2, i32* %6
br label %15
15: ; preds = %28, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %6
%18 = mul nsw i32 %16, %17
%19 = load i32, i32* %3
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = load i32, i32* %3
%23 = load i32, i32* %6
%24 = srem i32 %22, %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %7
br label %31
27: ; preds = %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %15
31: ; preds = %26, %15
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i8*
ret i8* %41
42: ; preds = %34
br label %43
43: ; preds = %42, %31
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %14
}

LLVM IR (-O2):
@.str = [36 x i8] c"Will compute for the %dth prime...\0A\00"
define i8* @compute_prime(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %20, %1
%6 = phi i32 [ 2, %1 ], [ %22, %20 ]
%7 = phi i32 [ %3, %1 ], [ %21, %20 ]
%8 = icmp ult i32 %6, 4
br i1 %8, label %17, label %12
9: ; preds = %12
%10 = mul nsw i32 %16, %16
%11 = icmp ugt i32 %10, %6
br i1 %11, label %17, label %12
12: ; preds = %5, %9
%13 = phi i32 [ %16, %9 ], [ 2, %5 ]
%14 = urem i32 %6, %13
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %13, 1
br i1 %15, label %20, label %9
17: ; preds = %9, %5
%18 = add nsw i32 %7, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %12, %17
%21 = phi i32 [ %18, %17 ], [ %7, %12 ]
%22 = add nuw nsw i32 %6, 1
br label %5
23: ; preds = %17
%24 = zext i32 %6 to i64
%25 = inttoptr i64 %24 to i8*
ret i8* %25
}