#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);
int check_prime(int num) {
  int flag = 0, i;
  if (num == 2)
    flag = 0;
  else {
    for (i = 2; i <= num / 2; i++) {
      printf("i = %d, n=%d\n", i, num);
      if (num % i == 0)
        flag = 1;
    }
  }
  return flag;
}


x86 assembly (clang, -O0):
<check_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    1138 <check_prime+0x28>
movl   $0x0,-0x8(%rbp)
jmp    119e <check_prime+0x8e>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1199 <check_prime+0x89>
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1186 <check_prime+0x76>
movl   $0x1,-0x8(%rbp)
jmp    118b <check_prime+0x7b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <check_prime+0x2f>
jmp    119e <check_prime+0x8e>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_prime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
cmp    $0x4,%edi
jge    1128 <check_prime+0x18>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%r12d
mov    %edi,%r15d
shr    %r15d
neg    %r15d
xor    %ebp,%ebp
mov    $0x2,%ebx
lea    0xebe(%rip),%r14
jmp    1165 <check_prime+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%ecx
add    $0x1,%ecx
mov    %ebx,%edx
add    $0x1,%edx
mov    %edx,%ebx
mov    %eax,%ebp
cmp    $0x1,%ecx
je     111f <check_prime+0xf>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
call   1030 <printf@plt>
mov    %r12d,%eax
cltd
idiv   %ebx
mov    $0x1,%eax
test   %edx,%edx
je     1150 <check_prime+0x40>
mov    %ebp,%eax
jmp    1150 <check_prime+0x40>

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

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