#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int test(int);
int main(int argc, char **argv) {
  if (argc == 1) {
    printf("please call me like './prime range'\n");
    return 0;
  }
  int range = atoi(argv[1]);
  int primes[(100 + range / 6)];
  int primdex = 0;
  for (int i = 0; i < range; i++) {
    if (test(i) == 1) {
      primes[primdex] = i;
      primdex++;
    }
  }
  printf("%d \n", primdex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
mov    %ecx,%edx
shr    $0x3f,%rax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x64(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1213 <main+0xe3>
mov    -0x30(%rbp),%edi
call   1050 <test@plt>
cmp    $0x1,%eax
jne    1200 <main+0xd0>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1205 <main+0xd5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11cc <main+0x9c>
mov    -0x2c(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    115a <main+0x1a>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x70>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %rsp,%r15
test   %eax,%eax
jle    119b <main+0x5b>
mov    %eax,%r14d
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <test@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1180 <main+0x40>
jmp    119d <main+0x5d>
xor    %ebx,%ebx
lea    0xe5c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"please call me like './prime range'\0A\00"
@.str.1 = [5 x i8] c"%d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%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 eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %49
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = sdiv i32 %20, 6
%22 = add nsw i32 100, %21
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %7
%25 = alloca i32, i64 %23
store i64 %23, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %26
26: ; preds = %42, %15
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load i32, i32* %10
%32 = call i32 @test(i32 %31)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* %10
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %25, i64 %37
store i32 %35, i32* %38
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %41
41: ; preds = %34, %30
br label %42
42: ; preds = %41
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %26
45: ; preds = %26
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
store i32 0, i32* %3
%48 = load i8*, i8** %7
br label %49
49: ; preds = %45, %13
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d \0A\00"
@str = [36 x i8] c"please call me like './prime range'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %24
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 i8* @llvm.stacksave()
%11 = icmp sgt i32 %9, 0
br i1 %11, label %15, label %12
12: ; preds = %15, %6
%13 = phi i32 [ 0, %6 ], [ %21, %15 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
tail call void @llvm.stackrestore(i8* %10)
br label %24
15: ; preds = %6, %15
%16 = phi i32 [ %22, %15 ], [ 0, %6 ]
%17 = phi i32 [ %21, %15 ], [ 0, %6 ]
%18 = tail call i32 @test(i32 %16)
%19 = icmp eq i32 %18, 1
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %17, %20
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, %9
br i1 %23, label %12, label %15
24: ; preds = %12, %4
ret i32 0
}