#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*/ scanf(char *, int *);
int check_prime(int num) {
  int i = 2, n;
  scanf("%d", &n);
  while (i <= num - 1) {
    if (n % i == 0)
      return 0;
    i = i + 1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
lea    0xed7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     116d <check_prime+0x5d>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    115f <check_prime+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1174 <check_prime+0x64>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <check_prime+0x22>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_prime>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xee2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1030 <scanf@plt>
mov    $0x1,%ecx
cmp    $0x3,%ebx
jl     1154 <check_prime+0x44>
mov    $0x2,%edi
mov    0xc(%rsp),%esi
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1152 <check_prime+0x42>
add    $0x1,%edi
cmp    %edi,%ebx
jne    1140 <check_prime+0x30>
jmp    1154 <check_prime+0x44>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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