#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 */
void *compute_prime(void *arg) {
  int candidate = 2;
  int n = *((int *)arg);
  while (1) {
    int factor;
    int is_prime = 1;
    for (factor = 2; 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
mov    %rdi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1161 <compute_prime+0x61>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    114e <compute_prime+0x4e>
movl   $0x0,-0x18(%rbp)
jmp    1161 <compute_prime+0x61>
jmp    1153 <compute_prime+0x53>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <compute_prime+0x26>
cmpl   $0x0,-0x18(%rbp)
je     1188 <compute_prime+0x88>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1183 <compute_prime+0x83>
movslq -0xc(%rbp),%rax
pop    %rbp
ret
jmp    1188 <compute_prime+0x88>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1118 <compute_prime+0x18>

x86 assembly (clang, -O2):
<compute_prime>:
mov    (%rdi),%r8d
mov    $0x2,%ecx
xor    %edi,%edi
jmp    111c <compute_prime+0x1c>
nopl   0x0(%rax)
add    $0xffffffff,%r8d
je     1147 <compute_prime+0x47>
add    $0x1,%ecx
add    $0xffffffff,%edi
cmp    $0x3,%ecx
jb     1110 <compute_prime+0x10>
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     1116 <compute_prime+0x16>
add    $0x1,%esi
lea    (%rdi,%rsi,1),%eax
cmp    $0x2,%eax
jne    1130 <compute_prime+0x30>
jmp    1110 <compute_prime+0x10>
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i8* @compute_prime(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 2, i32* %3
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %4
br label %10
10: ; preds = %1, %37
store i32 1, i32* %6
store i32 2, i32* %5
br label %11
11: ; preds = %22, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %3
%17 = load i32, i32* %5
%18 = srem i32 %16, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 0, i32* %6
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %11
25: ; preds = %20, %11
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
ret i8* %35
36: ; preds = %28
br label %37
37: ; preds = %36, %25
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %10
}

LLVM IR (-O2):
define i8* @compute_prime(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
br label %4
4: ; preds = %18, %1
%5 = phi i32 [ 2, %1 ], [ %20, %18 ]
%6 = phi i32 [ %3, %1 ], [ %19, %18 ]
%7 = icmp ugt i32 %5, 2
br i1 %7, label %10, label %15
8: ; preds = %10
%9 = icmp eq i32 %14, %5
br i1 %9, label %15, label %10
10: ; preds = %4, %8
%11 = phi i32 [ %14, %8 ], [ 2, %4 ]
%12 = urem i32 %5, %11
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i32 %11, 1
br i1 %13, label %18, label %8
15: ; preds = %8, %4
%16 = add nsw i32 %6, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10, %15
%19 = phi i32 [ %16, %15 ], [ %6, %10 ]
%20 = add nuw nsw i32 %5, 1
br label %4
21: ; preds = %15
%22 = zext i32 %5 to i64
%23 = inttoptr i64 %22 to i8*
ret i8* %23
}