#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 */
long *create_matrix(long);
int /*<<< orphan*/ fill_matrix(long *, long);
int /*<<< orphan*/ free(long *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, long *);
int /*<<< orphan*/ sieve(long *, long);
int /*<<< orphan*/ write_out(long *, long);
int main(void) {
  long int *matrix;
  long int i;
  long int range;
  printf("Poszukiwanie liczb pierwszych w przedziale 0 - ");
  scanf("%d", &range);
  matrix = create_matrix(range);
  if (matrix == NULL) {
    return 0;
  }
  fill_matrix(matrix, range);
  sieve(matrix, range);
  write_out(matrix, range);
  free(matrix);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1060 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <create_matrix@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <main+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <main+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fill_matrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <sieve@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <write_out@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
call   1060 <printf@plt>
lea    0xea8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x8(%rsp),%rdi
call   1040 <create_matrix@plt>
test   %rax,%rax
je     11d3 <main+0x63>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <fill_matrix@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <sieve@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <write_out@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Poszukiwanie liczb pierwszych w przedziale 0 - \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%7 = load i64, i64* %4
%8 = call i64* @create_matrix(i64 %7)
store i64* %8, i64** %2
%9 = load i64*, i64** %2
%10 = icmp eq i64* %9, null
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 0, i32* %1
br label %24
12: ; preds = %0
%13 = load i64*, i64** %2
%14 = load i64, i64* %4
%15 = call i32 @fill_matrix(i64* %13, i64 %14)
%16 = load i64*, i64** %2
%17 = load i64, i64* %4
%18 = call i32 @sieve(i64* %16, i64 %17)
%19 = load i64*, i64** %2
%20 = load i64, i64* %4
%21 = call i32 @write_out(i64* %19, i64 %20)
%22 = load i64*, i64** %2
%23 = call i32 @free(i64* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %12, %11
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [48 x i8] c"Poszukiwanie liczb pierwszych w przedziale 0 - \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = call i64* @create_matrix(i64 %5)
%7 = icmp eq i64* %6, null
br i1 %7, label %16, label %8
8: ; preds = %0
%9 = load i64, i64* %1
%10 = call i32 @fill_matrix(i64* %6, i64 %9)
%11 = load i64, i64* %1
%12 = call i32 @sieve(i64* %6, i64 %11)
%13 = load i64, i64* %1
%14 = call i32 @write_out(i64* %6, i64 %13)
%15 = call i32 @free(i64* %6)
br label %16
16: ; preds = %0, %8
ret i32 0
}