#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;
long atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(long *);
int /*<<< orphan*/ printf(char *, long);
long *sieve(long);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc - 1 != 1) {
    fprintf(stderr, "Error %s Requres 1 Argument\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jjangsangy/Project-Euler/refs/heads/"
            "master/C/sieve.c");
    return EXIT_FAILURE;
  }
  long i = 0, max = atol(argv[1]);
  long *primes = sieve(max);
  while (primes[i])
    printf("%ld\n", primes[i++]);
  free(primes);
  return EXIT_SUCCESS;
}


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)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x1,%eax
je     11a2 <main+0x52>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
lea    0xe91(%rip),%rdx
call   1060 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1218 <main+0xc8>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <sieve@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1203 <main+0xb3>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax,%rcx,8),%rsi
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
jmp    11c8 <main+0x78>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11b5 <main+0x65>
mov    0x8(%rsi),%rdi
call   1070 <atol@plt>
mov    %rax,%rdi
call   1050 <sieve@plt>
mov    %rax,%r14
mov    (%rax),%rsi
test   %rsi,%rsi
je     11a4 <main+0x54>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xf28(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1190 <main+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e1d(%rip),%rax
jmp    11d8 <main+0x88>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
lea    0xe51(%rip),%rdx
call   1060 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Error %s Requres 1 Argument\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jjangsangy/Project-Euler/refs/heads/master/C/sieve.c\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%ld\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 i64
%7 = alloca i64
%8 = alloca i64*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %40
16: ; preds = %2
store i64 0, i64* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @atol(i8* %19)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = call i64* @sieve(i64 %21)
store i64* %22, i64** %8
br label %23
23: ; preds = %29, %16
%24 = load i64*, i64** %8
%25 = load i64, i64* %6
%26 = getelementptr inbounds i64, i64* %24, i64 %25
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i64*, i64** %8
%31 = load i64, i64* %6
%32 = add nsw i64 %31, 1
store i64 %32, i64* %6
%33 = getelementptr inbounds i64, i64* %30, i64 %31
%34 = load i64, i64* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %34)
br label %23
36: ; preds = %23
%37 = load i64*, i64** %8
%38 = call i32 @free(i64* %37)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %3
br label %40
40: ; preds = %36, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Error %s Requres 1 Argument\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jjangsangy/Project-Euler/refs/heads/master/C/sieve.c\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%ld\0A\00"
@EXIT_SUCCESS = global i32 0
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 i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0))
br label %24
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @atol(i8* %9)
%11 = tail call i64* @sieve(i64 %10)
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %7, %14
%15 = phi i64 [ %20, %14 ], [ %12, %7 ]
%16 = phi i64 [ %17, %14 ], [ 0, %7 ]
%17 = add nuw nsw i64 %16, 1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %15)
%19 = getelementptr inbounds i64, i64* %11, i64 %17
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %14
22: ; preds = %14, %7
%23 = tail call i32 @free(i64* %11)
br label %24
24: ; preds = %22, %4
%25 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %22 ]
%26 = load i32, i32* %25
ret i32 %26
}