#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 */
size_t atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sieve(char *, size_t);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage: %s N\n", *argv);
    return 0;
  }
  size_t i, n = atoi(argv[1]);
  char *a = malloc(n);
  sieve(a, n);
  for (i = 0; i < n; i++)
    if (a[i])
      printf("%ld\n", i);
  free(a);
  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   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <sieve@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    120c <main+0xbc>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11f6 <main+0xa6>
mov    -0x18(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fb <main+0xab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c4 <main+0x74>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11af <main+0x5f>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <sieve@plt>
test   %r14,%r14
je     11c2 <main+0x72>
lea    0xe82(%rip),%r15
xor    %ebx,%ebx
jmp    1199 <main+0x49>
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     11c2 <main+0x72>
cmpb   $0x0,(%r12,%rbx,1)
je     1190 <main+0x40>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <main+0x40>
mov    (%rsi),%rsi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ca <main+0x7a>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"usage: %s N\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
br label %45
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @atoi(i8* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = load i64, i64* %7
%24 = call i32 @sieve(i8* %22, i64 %23)
store i64 0, i64* %6
br label %25
25: ; preds = %39, %15
%26 = load i64, i64* %6
%27 = load i64, i64* %7
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i8*, i8** %8
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i64, i64* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %35, %29
br label %39
39: ; preds = %38
%40 = load i64, i64* %6
%41 = add i64 %40, 1
store i64 %41, i64* %6
br label %25
42: ; preds = %25
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"usage: %s N\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @atoi(i8* %9)
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 @sieve(i8* %11, i64 %10)
%13 = icmp eq i64 %10, 0
br i1 %13, label %24, label %14
14: ; preds = %7, %21
%15 = phi i64 [ %22, %21 ], [ 0, %7 ]
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %21
21: ; preds = %14, %19
%22 = add nuw i64 %15, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %24, label %14
24: ; preds = %21, %7
%25 = tail call i32 @free(i8* %11)
br label %26
26: ; preds = %24, %4
ret i32 0
}