#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int findprime(int, int /*<<< orphan*/, int *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int main() {
  int i;
  int bits;
  int primes[1000];
  FILE *fin, *fout;
  fin = fopen("sprime.in", "r");
  fout = fopen("sprime.out", "w");
  assert(fin && fout);
  fscanf(fin, "%d", &bits);
  memset(primes, 0, 1000 * sizeof(int));
  int index = findprime(bits, 0, primes, 0);
  for (i = 0; i < index; ++i) {
    fprintf(fout, "%d\n", primes[i]);
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xfb8(%rbp)
lea    0xe69(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xfc0(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0xfb8(%rbp)
mov    %al,-0xfc5(%rbp)
je     11dd <main+0x6d>
cmpq   $0x0,-0xfc0(%rbp)
setne  %al
mov    %al,-0xfc5(%rbp)
mov    -0xfc5(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0xfb8(%rbp),%rdi
lea    0xe1e(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
lea    -0xfb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0xfb0(%rbp),%rdx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1080 <findprime@plt>
mov    %eax,-0xfc4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xfc4(%rbp),%eax
jge    1272 <main+0x102>
mov    -0xfc0(%rbp),%rdi
movslq -0x8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%edx
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1237 <main+0xc7>
mov    -0xfb8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xfc0(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb0,%rsp
lea    0xe79(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe6f(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %r14,%r14
setne  %al
test   %r15,%r15
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
lea    0xe50(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1080 <findprime@plt>
test   %eax,%eax
jle    1228 <main+0xb8>
mov    %eax,%r13d
xor    %ebx,%ebx
lea    0xe12(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1210 <main+0xa0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"sprime.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"sprime.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i32]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br label %15
15: ; preds = %12, %0
%16 = phi i1 [ false, %0 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %5
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%22 = call i32 @memset(i32* %21, i32 0, i32 4000)
%23 = load i32, i32* %3
%24 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%25 = call i32 @findprime(i32 %23, i32 0, i32* %24, i32 0)
store i32 %25, i32* %7
store i32 0, i32* %2
br label %26
26: ; preds = %37, %15
%27 = load i32, i32* %2
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %26
40: ; preds = %26
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"sprime.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"sprime.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [1000 x i32]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp ne i32* %5, null
%8 = icmp ne i32* %6, null
%9 = and i1 %7, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%14 = call i32 @memset(i32* %13, i32 0, i32 4000)
%15 = load i32, i32* %1
%16 = call i32 @findprime(i32 %15, i32 0, i32* %13, i32 0)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %0
%19 = zext i32 %16 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20, %0
%28 = call i32 @fclose(i32* %5)
%29 = call i32 @fclose(i32* %6)
ret i32 0
}