#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 is_prime(int num) {
  int sim = 2;
  if (num >= 2) {
    while (num % sim != 0) {
      sim++;
    }
    if (sim == num)
      printf("1");
    else
      printf("0");
  } else
    printf("-1");
}


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     117d <is_prime+0x6d>
jmp    1131 <is_prime+0x21>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
je     114f <is_prime+0x3f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <is_prime+0x21>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    116c <is_prime+0x5c>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    1178 <is_prime+0x68>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
jmp    1189 <is_prime+0x79>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rax
cmp    $0x2,%edi
jl     114a <is_prime+0x2a>
mov    $0x2,%ecx
nopl   0x0(%rax,%rax,1)
mov    %edi,%eax
cltd
idiv   %ecx
add    $0x1,%ecx
test   %edx,%edx
jne    1130 <is_prime+0x10>
sub    %edi,%ecx
cmp    $0x1,%ecx
jne    1158 <is_prime+0x38>
mov    $0x31,%edi
jmp    115d <is_prime+0x3d>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
pop    %rcx
ret
mov    $0x30,%edi
call   1030 <putchar@plt>
pop    %rcx
ret

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

LLVM IR (-O2):
@.str.2 = [3 x i8] c"-1\00"
define i32 @is_prime(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %14
3: ; preds = %1, %3
%4 = phi i32 [ %7, %3 ], [ 2, %1 ]
%5 = srem i32 %0, %4
%6 = icmp eq i32 %5, 0
%7 = add nuw nsw i32 %4, 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = icmp eq i32 %4, %0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @putchar(i32 49)
br label %16
12: ; preds = %8
%13 = tail call i32 @putchar(i32 48)
br label %16
14: ; preds = %1
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %10, %12, %14
ret i32 undef
}