#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 main(int argc, char **argv) {
  int arg = argc > 1 ? argv[1][0] - '0' : 5;
  switch (arg) {
  case 0:
    return 0;
    break;
  case 1:
    arg = 33000;
    break;
  case 2:
    arg = 130000;
    break;
  case 3:
    arg = 220000;
    break;
  case 4:
    arg = 610000;
    break;
  case 5:
    arg = 1010000;
    break;
  default:
    printf("error: %d\\n", arg);
    return -1;
  }
  int primes = 0, curri = 2;
  while (primes < arg) {
    int ok = 1;
    for (int j = 2; j * j < curri; j++) {
      if (curri % j == 0) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      primes++;
    }
    curri++;
  }
  printf("lastprime: %d.\n", curri - 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1146 <main+0x36>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x28(%rbp)
jmp    1153 <main+0x43>
mov    $0x5,%eax
mov    %eax,-0x28(%rbp)
jmp    1153 <main+0x43>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x5,%rax
ja     11c6 <main+0xb6>
mov    -0x30(%rbp),%rax
lea    0xe8b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1282 <main+0x172>
movl   $0x80e8,-0x14(%rbp)
jmp    11e1 <main+0xd1>
movl   $0x1fbd0,-0x14(%rbp)
jmp    11e1 <main+0xd1>
movl   $0x35b60,-0x14(%rbp)
jmp    11e1 <main+0xd1>
movl   $0x94ed0,-0x14(%rbp)
jmp    11e1 <main+0xd1>
movl   $0xf6950,-0x14(%rbp)
jmp    11e1 <main+0xd1>
mov    -0x14(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <main+0x172>
movl   $0x0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1269 <main+0x159>
movl   $0x1,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1248 <main+0x138>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x24(%rbp)
cmp    $0x0,%edx
jne    1235 <main+0x125>
movl   $0x0,-0x20(%rbp)
jmp    1248 <main+0x138>
jmp    123a <main+0x12a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <main+0xf9>
cmpl   $0x0,-0x20(%rbp)
je     125b <main+0x14b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ef <main+0xdf>
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
lea    0xdae(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jl     1149 <main+0x39>
mov    0x8(%rsi),%rax
movsbl (%rax),%esi
add    $0xffffffd0,%esi
cmp    $0x5,%esi
ja     11b2 <main+0xa2>
mov    $0x80e8,%r8d
xor    %eax,%eax
lea    0xec8(%rip),%rcx
movslq (%rcx,%rsi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    $0x1fbd0,%r8d
jmp    114f <main+0x3f>
mov    $0xf6950,%r8d
xor    %r9d,%r9d
mov    $0x2,%eax
jmp    1171 <main+0x61>
nopl   0x0(%rax)
mov    $0x1,%edi
add    %edi,%r9d
lea    0x1(%r10),%eax
cmp    %r8d,%r9d
jae    119f <main+0x8f>
mov    %eax,%r10d
cmp    $0x5,%eax
jb     1160 <main+0x50>
mov    $0x3,%ecx
xchg   %ax,%ax
lea    -0x1(%rcx),%esi
xor    %edi,%edi
mov    %r10d,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     1165 <main+0x55>
mov    %ecx,%eax
imul   %ecx,%eax
add    $0x1,%ecx
cmp    %r10d,%eax
jb     1180 <main+0x70>
jmp    1160 <main+0x50>
lea    0xe7e(%rip),%rdi
mov    %r10d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    $0x35b60,%r8d
jmp    114f <main+0x3f>
mov    $0x94ed0,%r8d
jmp    114f <main+0x3f>

LLVM IR (-O0):
@.str = [12 x i8] c"error: %d\\n\00"
@.str.1 = [16 x i8] c"lastprime: %d.\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
br label %22
21: ; preds = %2
br label %22
22: ; preds = %21, %13
%23 = phi i32 [ %20, %13 ], [ 5, %21 ]
store i32 %23, i32* %6
%24 = load i32, i32* %6
switch i32 %24, label %31 [
i32 0, label %25
i32 1, label %26
i32 2, label %27
i32 3, label %28
i32 4, label %29
i32 5, label %30
]
25: ; preds = %22
store i32 0, i32* %3
br label %69
26: ; preds = %22
store i32 33000, i32* %6
br label %34
27: ; preds = %22
store i32 130000, i32* %6
br label %34
28: ; preds = %22
store i32 220000, i32* %6
br label %34
29: ; preds = %22
store i32 610000, i32* %6
br label %34
30: ; preds = %22
store i32 1010000, i32* %6
br label %34
31: ; preds = %22
%32 = load i32, i32* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 -1, i32* %3
br label %69
34: ; preds = %30, %29, %28, %27, %26
store i32 0, i32* %7
store i32 2, i32* %8
br label %35
35: ; preds = %62, %34
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %65
39: ; preds = %35
store i32 1, i32* %9
store i32 2, i32* %10
br label %40
40: ; preds = %53, %39
%41 = load i32, i32* %10
%42 = load i32, i32* %10
%43 = mul nsw i32 %41, %42
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %40
%47 = load i32, i32* %8
%48 = load i32, i32* %10
%49 = srem i32 %47, %48
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 0, i32* %9
br label %56
52: ; preds = %46
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %40
56: ; preds = %51, %40
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %35
65: ; preds = %35
%66 = load i32, i32* %8
%67 = sub nsw i32 %66, 1
%68 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %65, %31, %25
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [12 x i8] c"error: %d\\n\00"
@.str.1 = [16 x i8] c"lastprime: %d.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %13 [
i32 48, label %37
i32 49, label %16
i32 50, label %9
i32 51, label %10
i32 52, label %11
i32 53, label %12
]
9: ; preds = %4
br label %16
10: ; preds = %4
br label %16
11: ; preds = %4
br label %16
12: ; preds = %2, %4
br label %16
13: ; preds = %4
%14 = add nsw i32 %8, -48
%15 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %37
16: ; preds = %4, %12, %11, %10, %9
%17 = phi i32 [ 1010000, %12 ], [ 610000, %11 ], [ 220000, %10 ], [ 130000, %9 ], [ 33000, %4 ]
br label %18
18: ; preds = %16, %30
%19 = phi i32 [ 2, %16 ], [ %33, %30 ]
%20 = phi i32 [ 0, %16 ], [ %32, %30 ]
%21 = icmp ugt i32 %19, 4
br i1 %21, label %25, label %30
22: ; preds = %25
%23 = mul nsw i32 %29, %29
%24 = icmp ult i32 %23, %19
br i1 %24, label %25, label %30
25: ; preds = %18, %22
%26 = phi i32 [ %29, %22 ], [ 2, %18 ]
%27 = urem i32 %19, %26
%28 = icmp eq i32 %27, 0
%29 = add nuw nsw i32 %26, 1
br i1 %28, label %30, label %22
30: ; preds = %22, %25, %18
%31 = phi i32 [ 1, %18 ], [ 0, %25 ], [ 1, %22 ]
%32 = add nuw nsw i32 %20, %31
%33 = add nuw nsw i32 %19, 1
%34 = icmp ult i32 %32, %17
br i1 %34, label %18, label %35
35: ; preds = %30
%36 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %37
37: ; preds = %4, %35, %13
%38 = phi i32 [ -1, %13 ], [ 0, %35 ], [ 0, %4 ]
ret i32 %38
}