#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ is_prime(unsigned long);
int /*<<< orphan*/ prime_init(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write_primes(unsigned long, char *);
int main(int argc, char **argv) {
  unsigned long in = strtoul(argv[1], NULL, 10);
  write_primes(in, argv[2]);
  printf("Write Finished.\n");
  char buffer[20];
  printf("Enter file to scan: ");
  fflush(stdin);
  scanf("%s", buffer);
  prime_init(buffer);
  unsigned long l;
  while (1) {
    scanf("%lu", &l);
    printf("Is %lu prime: %d\n", l, is_prime(l));
  }
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <write_primes@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x30(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1090 <prime_init@plt>
lea    0xe2c(%rip),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <is_prime@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <main+0x86>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    0x10(%rbx),%rsi
mov    %rax,%rdi
call   1030 <write_primes@plt>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe3c(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   10a0 <prime_init@plt>
lea    0xe21(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe19(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <is_prime@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1210 <main+0x90>

LLVM IR (-O0):
@.str = [17 x i8] c"Write Finished.\0A\00"
@.str.1 = [21 x i8] c"Enter file to scan: \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%lu\00"
@.str.4 = [18 x i8] c"Is %lu prime: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [20 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @strtoul(i8* %11, i32* null, i32 10)
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @write_primes(i64 %13, i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stdin
%21 = call i32 @fflush(i32 %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%25 = call i32 @prime_init(i8* %24)
br label %26
26: ; preds = %2, %26
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %8)
%28 = load i64, i64* %8
%29 = load i64, i64* %8
%30 = call i32 @is_prime(i64 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %28, i32 %30)
br label %26
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Enter file to scan: \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%lu\00"
@.str.4 = [18 x i8] c"Is %lu prime: %d\0A\00"
@str = [16 x i8] c"Write Finished.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca i64
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strtoul(i8* nocapture %6, i32* null, i32 10)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @write_primes(i64 %7, i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = tail call i32 @fflush(i32 %14)
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%17 = call i32 @prime_init(i8* %12)
%18 = bitcast i64* %4 to i8*
br label %19
19: ; preds = %19, %2
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%21 = load i64, i64* %4
%22 = call i32 @is_prime(i64 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %21, i32 %22)
br label %19
}