#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*/ DumpArgs(int, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  DumpArgs(argc, argv);
  if (argc <= 1) {
    fprintf(stderr, "Invalid number of arguments passed to application, needs "
                    "a positive integer to check.\n");
    return 2;
  } else if (argc > 2) {
    fprintf(stderr, "Too many args passed to application, only one positive "
                    "integer can be provided.\n");
    return 2;
  }
  int num = 0;
  if (sscanf(argv[1], "%d", &num) != 1) {
    fprintf(stderr,
            "Invalid arg passed to application, must be a positive integer\n");
    return 2;
  }
  if (num < 0) {
    fprintf(
        stderr,
        "Invalid value passed to application, must be a positive integer\n");
    return 2;
  }
  if (num <= 2) {
    printf("%d is a prime\n", num);
    return 0;
  }
  int i = 2;
  int half = num / 2;
  for (; i <= half; ++i) {
    int mod = num % i;
    if (mod == 0) {
      printf("%d is not prime\n", num);
      return 1;
    }
  }
  printf("%d is a prime\n", num);
  return 0;
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <DumpArgs@plt>
cmpl   $0x1,-0x8(%rbp)
jg     118d <main+0x4d>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12cf <main+0x18f>
cmpl   $0x2,-0x8(%rbp)
jle    11b8 <main+0x78>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12cf <main+0x18f>
jmp    11bd <main+0x7d>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xed5(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1206 <main+0xc6>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12cf <main+0x18f>
cmpl   $0x0,-0x14(%rbp)
jge    1231 <main+0xf1>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12cf <main+0x18f>
cmpl   $0x2,-0x14(%rbp)
jg     1256 <main+0x116>
mov    -0x14(%rbp),%esi
lea    0xee6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cf <main+0x18f>
movl   $0x2,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     12b9 <main+0x179>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    12a6 <main+0x166>
mov    -0x14(%rbp),%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cf <main+0x18f>
jmp    12ab <main+0x16b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    126b <main+0x12b>
mov    -0x14(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1050 <DumpArgs@plt>
cmp    $0x1,%ebp
jg     1167 <main+0x27>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
jmp    120f <main+0xcf>
cmp    $0x2,%ebp
jne    11db <main+0x9b>
movl   $0x0,0x4(%rsp)
mov    0x8(%rbx),%rdi
lea    0xf29(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11ed <main+0xad>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     11ff <main+0xbf>
cmp    $0x2,%esi
jbe    11cb <main+0x8b>
cmp    $0x3,%esi
je     11cb <main+0x8b>
mov    %esi,%ecx
shr    %ecx
neg    %ecx
mov    $0x2,%edi
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1220 <main+0xe0>
lea    (%rcx,%rdi,1),%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0x1,%edx
mov    %edx,%edi
cmp    $0x1,%eax
jne    11b0 <main+0x70>
lea    0xf59(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1219 <main+0xd9>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
jmp    120f <main+0xcf>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
jmp    120f <main+0xcf>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xedb(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xf13(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    1219 <main+0xd9>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [87 x i8] c"Invalid number of arguments passed to application, needs a positive integer to check.\0A\00"
@.str.1 = [81 x i8] c"Too many args passed to application, only one positive integer can be provided.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [63 x i8] c"Invalid arg passed to application, must be a positive integer\0A\00"
@.str.4 = [65 x i8] c"Invalid value passed to application, must be a positive integer\0A\00"
@.str.5 = [15 x i8] c"%d is a prime\0A\00"
@.str.6 = [17 x i8] c"%d is not prime\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
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @DumpArgs(i32 %10, i8** %11)
%13 = load i32, i32* %4
%14 = icmp sle i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %69
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %69
24: ; preds = %18
br label %25
25: ; preds = %24
store i32 0, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %69
34: ; preds = %25
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %69
40: ; preds = %34
%41 = load i32, i32* %6
%42 = icmp sle i32 %41, 2
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %6
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %44)
store i32 0, i32* %3
br label %69
46: ; preds = %40
store i32 2, i32* %7
%47 = load i32, i32* %6
%48 = sdiv i32 %47, 2
store i32 %48, i32* %8
br label %49
49: ; preds = %63, %46
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = icmp sle i32 %50, %51
br i1 %52, label %53, label %66
53: ; preds = %49
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = srem i32 %54, %55
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* %6
%61 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %60)
store i32 1, i32* %3
br label %69
62: ; preds = %53
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %49
66: ; preds = %49
%67 = load i32, i32* %6
%68 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %66, %59, %43, %37, %31, %21, %15
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [87 x i8] c"Invalid number of arguments passed to application, needs a positive integer to check.\0A\00"
@.str.1 = [81 x i8] c"Too many args passed to application, only one positive integer can be provided.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [63 x i8] c"Invalid arg passed to application, must be a positive integer\0A\00"
@.str.4 = [65 x i8] c"Invalid value passed to application, must be a positive integer\0A\00"
@.str.5 = [15 x i8] c"%d is a prime\0A\00"
@.str.6 = [17 x i8] c"%d is not prime\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i32 @DumpArgs(i32 %0, i8** %1)
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
br label %50
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %50
14: ; preds = %9
%15 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0))
br label %48
23: ; preds = %14
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0))
br label %48
29: ; preds = %23
%30 = icmp ult i32 %24, 3
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %24)
br label %48
33: ; preds = %29
%34 = icmp eq i32 %24, 3
br i1 %34, label %46, label %35
35: ; preds = %33
%36 = lshr i32 %24, 1
br label %40
37: ; preds = %40
%38 = add nuw i32 %41, 1
%39 = icmp eq i32 %41, %36
br i1 %39, label %46, label %40
40: ; preds = %35, %37
%41 = phi i32 [ 2, %35 ], [ %38, %37 ]
%42 = srem i32 %24, %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %37
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %24)
br label %48
46: ; preds = %37, %33
%47 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %24)
br label %48
48: ; preds = %44, %46, %31, %26, %20
%49 = phi i32 [ 2, %20 ], [ 2, %26 ], [ 0, %31 ], [ 0, %46 ], [ 1, %44 ]
br label %50
50: ; preds = %48, %11, %6
%51 = phi i32 [ 2, %6 ], [ 2, %11 ], [ %49, %48 ]
ret i32 %51
}