#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ IsPrime(long);
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int primeCount = 0;
  int max;
  long int value = 2;
  if (argc != 2) {
    printf("Please insert the correct number of arguments\n");
    return EXIT_FAILURE;
  } else {
    max = atoi(argv[1]);
    printf("Max: %d\n", max);
  }
  while (true) {
    if (IsPrime(value)) {
      printf("%ld is prime and it's the %d\n", value, primeCount + 1);
      value++;
      primeCount++;
    } else {
      printf("%ld is not prime\n", value);
      value++;
    }
    if (primeCount == max) {
      return EXIT_SUCCESS;
    }
  }
}


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)
movl   $0x0,-0x14(%rbp)
movq   $0x2,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117e <main+0x4e>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1229 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a4 <main+0x74>
mov    -0x20(%rbp),%rdi
call   1040 <IsPrime@plt>
cmp    $0x0,%rax
je     11e9 <main+0xb9>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1207 <main+0xd7>
mov    -0x20(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1224 <main+0xf4>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1229 <main+0xf9>
jmp    11a4 <main+0x74>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11c7 <main+0x87>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
lea    0xe9d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
lea    0xeaf(%rip),%r14
mov    0x2e59(%rip),%r13
lea    0xe83(%rip),%r15
xor    %ebp,%ebp
jmp    11a6 <main+0x66>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %r12d,%ebp
je     11da <main+0x9a>
mov    %rbx,%rdi
call   1050 <IsPrime@plt>
test   %rax,%rax
je     1190 <main+0x50>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119d <main+0x5d>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e06(%rip),%r13
mov    0x0(%r13),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Please insert the correct number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"Max: %d\0A\00"
@.str.2 = [30 x i8] c"%ld is prime and it's the %d\0A\00"
@.str.3 = [18 x i8] c"%ld is not prime\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i64 2, i64* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %47
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %14
br label %22
22: ; preds = %21, %46
%23 = load i64, i64* %8
%24 = call i64 @IsPrime(i64 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i64, i64* %8
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %27, i32 %29)
%31 = load i64, i64* %8
%32 = add nsw i64 %31, 1
store i64 %32, i64* %8
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %40
35: ; preds = %22
%36 = load i64, i64* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %36)
%38 = load i64, i64* %8
%39 = add nsw i64 %38, 1
store i64 %39, i64* %8
br label %40
40: ; preds = %35, %26
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %3
br label %47
46: ; preds = %40
br label %22
47: ; preds = %44, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"Max: %d\0A\00"
@.str.2 = [30 x i8] c"%ld is prime and it's the %d\0A\00"
@.str.3 = [18 x i8] c"%ld is not prime\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [46 x i8] c"Please insert the correct number of arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %25
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %21, %6
%12 = phi i32 [ 0, %6 ], [ %22, %21 ]
%13 = phi i64 [ 2, %6 ], [ %23, %21 ]
%14 = tail call i64 @IsPrime(i64 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = add nsw i32 %12, 1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %13, i32 %17)
br label %21
19: ; preds = %11
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %13)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %17, %16 ], [ %12, %19 ]
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i32 %22, %9
br i1 %24, label %25, label %11
25: ; preds = %21, %4
%26 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %21 ]
%27 = load i32, i32* %26
ret i32 %27
}