#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 a) {
  int i, flag = 0;
  for (i = 2; i <= a / 2; ++i) {
    if (a % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    printf("1");
  else
    printf("0");
}


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1176 <is_prime+0x66>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1163 <is_prime+0x53>
movl   $0x1,-0x10(%rbp)
jmp    1176 <is_prime+0x66>
jmp    1168 <is_prime+0x58>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <is_prime+0x19>
cmpl   $0x0,-0x10(%rbp)
jne    1191 <is_prime+0x81>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
jmp    119d <is_prime+0x8d>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
mov    %edi,%r8d
mov    $0x31,%edi
cmp    $0x4,%r8d
jl     1148 <is_prime+0x38>
mov    %r8d,%esi
shr    %esi
neg    %esi
mov    $0x2,%ecx
nopw   0x0(%rax,%rax,1)
mov    %r8d,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     114d <is_prime+0x3d>
lea    (%rsi,%rcx,1),%eax
add    $0x1,%eax
add    $0x1,%ecx
cmp    $0x1,%eax
jne    1130 <is_prime+0x20>
jmp    1030 <putchar@plt>
mov    $0x30,%edi
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define i32 @is_prime(i32 %0) {
%2 = icmp slt i32 %0, 4
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = lshr i32 %0, 1
br label %8
5: ; preds = %8
%6 = add nuw nsw i32 %9, 1
%7 = icmp eq i32 %9, %4
br i1 %7, label %12, label %8
8: ; preds = %3, %5
%9 = phi i32 [ %6, %5 ], [ 2, %3 ]
%10 = srem i32 %0, %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %8, %5, %1
%13 = phi i32 [ 49, %1 ], [ 49, %5 ], [ 48, %8 ]
%14 = tail call i32 @putchar(i32 %13)
ret i32 undef
}