#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);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
void *thr_primer(void *p) {
  int i, j, mark;
  i = (int)p;
  mark = 1;
  for (j = 2; j < i / 2; j++) {
    if (i % j == 0) {
      mark = 0;
      break;
    }
  }
  if (mark)
    printf("%d is a primer.\n", i);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<thr_primer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    118e <thr_primer+0x6e>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    117b <thr_primer+0x5b>
movl   $0x0,-0x1c(%rbp)
jmp    118e <thr_primer+0x6e>
jmp    1180 <thr_primer+0x60>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1141 <thr_primer+0x21>
cmpl   $0x0,-0x1c(%rbp)
je     11a7 <thr_primer+0x87>
mov    -0x14(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_primer>:
mov    %rdi,%rsi
cmp    $0x6,%esi
jl     1150 <thr_primer+0x30>
mov    %esi,%ecx
shr    %ecx
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1161 <thr_primer+0x41>
add    $0x1,%edi
cmp    %edi,%ecx
jne    1140 <thr_primer+0x20>
push   %rax
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
xor    %edi,%edi
jmp    1040 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"%d is a primer.\0A\00"
define i8* @thr_primer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %4
store i32 1, i32* %6
store i32 2, i32* %5
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = sdiv i32 %11, 2
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = srem i32 %15, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %6
br label %24
20: ; preds = %14
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %9
24: ; preds = %19, %9
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
%31 = call i32 @pthread_exit(i32* null)
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"%d is a primer.\0A\00"
define noalias i8* @thr_primer(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = icmp sgt i32 %3, 5
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = lshr i32 %3, 1
br label %9
7: ; preds = %9
%8 = icmp eq i32 %13, %6
br i1 %8, label %14, label %9
9: ; preds = %5, %7
%10 = phi i32 [ %13, %7 ], [ 2, %5 ]
%11 = srem i32 %3, %10
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %16, label %7
14: ; preds = %7, %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %16
16: ; preds = %9, %14
%17 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}