#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 scanf(char *, int *);
int main(int argc, char *argv[]) {
  int num;
  int arg;
  int prime;
  int itr;
  while (1) {
    printf("Enter an integer, 0 to exit\n");
    arg = scanf("%d", &num);
    if (arg <= 0) {
      printf("Not an int\n\n");
    } else if (num == 0) {
      return 0;
    } else {
      if (num < 0)
        num *= -1;
      prime = 0;
      for (itr = 2; itr < num; itr++) {
        if (num % itr == 0)
          prime = 1;
      }
      if (prime == 1)
        printf("%d is not prime\n\n", num);
      else
        printf("%d is prime\n\n", num);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     1174 <main+0x54>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <main+0xf6>
cmpl   $0x0,-0x14(%rbp)
jne    1186 <main+0x66>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x14(%rbp)
jge    1197 <main+0x77>
imul   $0xffffffff,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11db <main+0xbb>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x20(%rbp)
cmp    $0x0,%edx
jne    11c8 <main+0xa8>
movl   $0x1,-0x1c(%rbp)
jmp    11cd <main+0xad>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a5 <main+0x85>
cmpl   $0x1,-0x1c(%rbp)
jne    11fb <main+0xdb>
mov    -0x14(%rbp),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120c <main+0xec>
mov    -0x14(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1211 <main+0xf1>
jmp    1216 <main+0xf6>
jmp    1136 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee1(%rip),%r14
lea    0xeb7(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xeea(%rip),%rbx
mov    $0x1,%r13d
lea    0xeb3(%rip),%rbp
jmp    1178 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
test   %eax,%eax
jle    1170 <main+0x40>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     124f <main+0x11f>
js     11b0 <main+0x80>
cmp    $0x3,%esi
jae    11bf <main+0x8f>
jmp    1240 <main+0x110>
nopw   0x0(%rax,%rax,1)
neg    %esi
mov    %esi,0x4(%rsp)
cmp    $0x3,%esi
jb     1240 <main+0x110>
jne    11d0 <main+0xa0>
xor    %edi,%edi
mov    $0x2,%ecx
test   $0x1,%sil
jne    1221 <main+0xf1>
jmp    122c <main+0xfc>
mov    %rbp,%r10
mov    %rbx,%r9
lea    -0x2(%rsi),%r8d
and    $0xfffffffe,%r8d
xor    %edi,%edi
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebx
mov    %esi,%eax
cltd
idiv   %ecx
mov    %edx,%ecx
lea    0x1(%rbx),%ebp
mov    %esi,%eax
cltd
idiv   %ebp
test   %ecx,%ecx
cmove  %r13d,%edi
test   %edx,%edx
cmove  %r13d,%edi
lea    0x2(%rbx),%ecx
cmp    %r8d,%ebx
jne    11f0 <main+0xc0>
mov    %r9,%rbx
mov    %r10,%rbp
test   $0x1,%sil
je     122c <main+0xfc>
mov    %esi,%eax
cltd
idiv   %ecx
test   %edx,%edx
cmove  %r13d,%edi
cmp    $0x1,%edi
jne    1240 <main+0x110>
lea    0xdcb(%rip),%rdi
jmp    1243 <main+0x113>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1178 <main+0x48>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Enter an integer, 0 to exit\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Not an int\0A\0A\00"
@.str.3 = [18 x i8] c"%d is not prime\0A\0A\00"
@.str.4 = [14 x i8] c"%d is prime\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %2, %53
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %53
17: ; preds = %10
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
ret i32 0
21: ; preds = %17
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %6
%26 = mul nsw i32 %25, -1
store i32 %26, i32* %6
br label %27
27: ; preds = %24, %21
store i32 0, i32* %8
store i32 2, i32* %9
br label %28
28: ; preds = %39, %27
%29 = load i32, i32* %9
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %6
%34 = load i32, i32* %9
%35 = srem i32 %33, %34
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %8
br label %38
38: ; preds = %37, %32
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %28
42: ; preds = %28
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %51
48: ; preds = %42
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52, %15
br label %10
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"%d is not prime\0A\0A\00"
@.str.4 = [14 x i8] c"%d is prime\0A\0A\00"
@str = [28 x i8] c"Enter an integer, 0 to exit\00"
@str.5 = [12 x i8] c"Not an int\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %58, %2
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %58
11: ; preds = %5
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
ret i32 0
15: ; preds = %11
%16 = icmp slt i32 %12, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = sub nsw i32 0, %12
store i32 %18, i32* %3
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %18, %17 ], [ %12, %15 ]
%21 = icmp ugt i32 %20, 2
br i1 %21, label %22, label %56
22: ; preds = %19
%23 = and i32 %20, 1
%24 = icmp eq i32 %20, 3
br i1 %24, label %42, label %25
25: ; preds = %22
%26 = add i32 %20, -2
%27 = and i32 %26, -2
br label %28
28: ; preds = %28, %25
%29 = phi i32 [ 2, %25 ], [ %39, %28 ]
%30 = phi i32 [ 0, %25 ], [ %38, %28 ]
%31 = phi i32 [ 0, %25 ], [ %40, %28 ]
%32 = srem i32 %20, %29
%33 = icmp eq i32 %32, 0
%34 = or i32 %29, 1
%35 = srem i32 %20, %34
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i1 true, i1 %33
%38 = select i1 %37, i32 1, i32 %30
%39 = add nuw nsw i32 %29, 2
%40 = add i32 %31, 2
%41 = icmp eq i32 %40, %27
br i1 %41, label %42, label %28
42: ; preds = %28, %22
%43 = phi i32 [ undef, %22 ], [ %38, %28 ]
%44 = phi i32 [ 2, %22 ], [ %39, %28 ]
%45 = phi i32 [ 0, %22 ], [ %38, %28 ]
%46 = icmp eq i32 %23, 0
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = srem i32 %20, %44
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i32 1, i32 %45
br label %51
51: ; preds = %42, %47
%52 = phi i32 [ %43, %42 ], [ %50, %47 ]
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %58
56: ; preds = %19, %51
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %58
58: ; preds = %56, %54, %9
br label %5
}