#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;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned int *);
int getopt(int, char **, char *);
unsigned int *malloc(size_t);
scalar_t__ opterr;
int optind;
int /*<<< orphan*/ primes(size_t, unsigned int *);
scalar_t__ primes_file(size_t, char *);
int /*<<< orphan*/ primes_verbose(size_t, unsigned int *);
int sscanf(char *, char *, size_t *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  bool verbose = false;
  int c;
  opterr = 0;
  while ((c = getopt(argc, argv, "hv")) != -1) {
    switch (c) {
    case 'h':
      fprintf(
          stdout,
          "NAME\n"
          "       prime - computes prime numbers\n"
          "\n"
          "SYNOPSIS\n"
          "       %s [-h] [-v] primes [output]\n"
          "\n"
          "DESCRIPTION\n"
          "       Takes the number of primes to generate and uses the rather\n"
          "       non-optimized algorithm found at\n"
          "           "
          "http://docs.cython.org/src/tutorial/cython_tutorial.html\n"
          "\n"
          "OPTIONS\n"
          "       -h      Display this message.\n"
          "\n"
          "       -v      Enable verbose output.  Prints each prime to the "
          "terminal\n"
          "               instead of just the last.  Does not apply if an "
          "output file\n"
          "               is given.\n"
          "\n"
          "       If the output argument is given the entire list of prime "
          "numbers\n"
          "       generated will be written as 4 byte unsigned integers to "
          "the\n"
          "       specified file.\n"
          "\n"
          "updated: Friday, April 03, 2015\n",
          argv[0]);
      return EXIT_SUCCESS;
      break;
    case 'v':
      verbose = true;
      break;
    }
  }
  if (optind >= argc) {
    fprintf(stderr, "Expected number of primes.\n");
    return EXIT_FAILURE;
  }
  size_t num_primes = 0;
  if (sscanf(argv[optind++], "%zu", &num_primes) != 1) {
    fprintf(stderr, "Expected integer argument for primes.\n");
  }
  if (optind < argc) {
    if (primes_file(num_primes, argv[optind++])) {
      return EXIT_FAILURE;
    } else {
      return EXIT_SUCCESS;
    }
  }
  unsigned int *prime_nums = malloc(num_primes * sizeof(unsigned int));
  if (prime_nums == NULL) {
    fprintf(stderr, "ERROR: Failed to allocate memory.\n");
    return EXIT_FAILURE;
  }
  if (verbose) {
    primes_verbose(num_primes, prime_nums);
  } else {
    primes(num_primes, prime_nums);
  }
  free(prime_nums);
  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)
movl   $0x0,-0x14(%rbp)
mov    0x2e24(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     122a <main+0xaa>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x68,%eax
je     11ef <main+0x6f>
jmp    11de <main+0x5e>
mov    -0x2c(%rbp),%eax
sub    $0x76,%eax
je     121e <main+0x9e>
jmp    1225 <main+0xa5>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a9 <main+0x229>
movl   $0x1,-0x14(%rbp)
jmp    11ab <main+0x2b>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1264 <main+0xe4>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0x106d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a9 <main+0x229>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d71(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d63(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0x1040(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     12be <main+0x13e>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0x1022(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1327 <main+0x1a7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2d09(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2cfb(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <primes_file@plt>
cmp    $0x0,%rax
je     1316 <main+0x196>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a9 <main+0x229>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a9 <main+0x229>
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    136b <main+0x1eb>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xfad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a9 <main+0x229>
cmpl   $0x0,-0x14(%rbp)
je     1387 <main+0x207>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <primes_verbose@plt>
jmp    1394 <main+0x214>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <primes@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c14(%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   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e30(%rip),%rax
movq   $0x0,(%rax)
mov    $0x1,%r12b
lea    0xe57(%rip),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11d3 <main+0x53>
cmp    $0x76,%eax
je     11ce <main+0x4e>
cmp    $0x68,%eax
jne    11b0 <main+0x30>
jmp    1248 <main+0xc8>
xor    %r12d,%r12d
jmp    11b0 <main+0x30>
mov    0x2e0e(%rip),%rbx
movslq (%rbx),%rax
cmp    %ebp,%eax
jge    126b <main+0xeb>
movq   $0x0,0x8(%rsp)
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
mov    (%r15,%rax,8),%rdi
lea    0x10d7(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     1224 <main+0xa4>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0x10bc(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movslq (%rbx),%rax
mov    0x8(%rsp),%r14
cmp    %ebp,%eax
jge    1298 <main+0x118>
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
mov    (%r15,%rax,8),%rsi
mov    %r14,%rdi
call   1060 <primes_file@plt>
test   %rax,%rax
jne    1282 <main+0x102>
jmp    1262 <main+0xe2>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d4f(%rip),%rax
jmp    1289 <main+0x109>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0x103e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x0(,%r14,4),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     12c0 <main+0x140>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
test   $0x1,%r12b
je     12d2 <main+0x152>
call   10a0 <primes@plt>
jmp    12d7 <main+0x157>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0x1030(%rip),%rsi
jmp    127b <main+0xfb>
call   1040 <primes_verbose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1262 <main+0xe2>

LLVM IR (-O0):
@opterr = global i64 0
@.str = [3 x i8] c"hv\00"
@stdout = global i32 0
@.str.1 = [694 x i8] c"NAME\0A prime - computes prime numbers\0A\0ASYNOPSIS\0A %s [-h] [-v] primes [output]\0A\0ADESCRIPTION\0A Takes the number of primes to generate and uses the rather\0A non-optimized algorithm found at\0A http://docs.cython.org/src/tutorial/cython_tutorial.html\0A\0AOPTIONS\0A -h Display this message.\0A\0A -v Enable verbose output. Prints each prime to the terminal\0A instead of just the last. Does not apply if an output file\0A is given.\0A\0A If the output argument is given the entire list of prime numbers\0A generated will be written as 4 byte unsigned integers to the\0A specified file.\0A\0Aupdated: Friday, April 03, 2015\0A\00"
@EXIT_SUCCESS = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Expected number of primes.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%zu\00"
@.str.4 = [39 x i8] c"Expected integer argument for primes.\0A\00"
@.str.5 = [35 x i8] c"ERROR: Failed to allocate memory.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i64 0, i64* @opterr
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %25 [
i32 104, label %17
i32 118, label %24
]
17: ; preds = %15
%18 = load i32, i32* @stdout
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([694 x i8], [694 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %3
br label %89
24: ; preds = %15
store i32 1, i32* %6
br label %25
25: ; preds = %15, %24
br label %10
26: ; preds = %10
%27 = load i32, i32* @optind
%28 = load i32, i32* %4
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %3
br label %89
34: ; preds = %26
store i64 0, i64* %8
%35 = load i8**, i8*** %5
%36 = load i32, i32* @optind
%37 = add nsw i32 %36, 1
store i32 %37, i32* @optind
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8*, i8** %35, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %8)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %43, %34
%47 = load i32, i32* @optind
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %64
50: ; preds = %46
%51 = load i64, i64* %8
%52 = load i8**, i8*** %5
%53 = load i32, i32* @optind
%54 = add nsw i32 %53, 1
store i32 %54, i32* @optind
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8*, i8** %52, i64 %55
%57 = load i8*, i8** %56
%58 = call i64 @primes_file(i64 %51, i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %50
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %89
62: ; preds = %50
%63 = load i32, i32* @EXIT_SUCCESS
store i32 %63, i32* %3
br label %89
64: ; preds = %46
%65 = load i64, i64* %8
%66 = mul i64 %65, 4
%67 = call i32* @malloc(i64 %66)
store i32* %67, i32** %9
%68 = load i32*, i32** %9
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %3
br label %89
74: ; preds = %64
%75 = load i32, i32* %6
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %74
%78 = load i64, i64* %8
%79 = load i32*, i32** %9
%80 = call i32 @primes_verbose(i64 %78, i32* %79)
br label %85
81: ; preds = %74
%82 = load i64, i64* %8
%83 = load i32*, i32** %9
%84 = call i32 @primes(i64 %82, i32* %83)
br label %85
85: ; preds = %81, %77
%86 = load i32*, i32** %9
%87 = call i32 @free(i32* %86)
%88 = load i32, i32* @EXIT_SUCCESS
store i32 %88, i32* %3
br label %89
89: ; preds = %85, %70, %62, %60, %30, %17
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [3 x i8] c"hv\00"
@stdout = global i32 0
@.str.1 = [694 x i8] c"NAME\0A prime - computes prime numbers\0A\0ASYNOPSIS\0A %s [-h] [-v] primes [output]\0A\0ADESCRIPTION\0A Takes the number of primes to generate and uses the rather\0A non-optimized algorithm found at\0A http://docs.cython.org/src/tutorial/cython_tutorial.html\0A\0AOPTIONS\0A -h Display this message.\0A\0A -v Enable verbose output. Prints each prime to the terminal\0A instead of just the last. Does not apply if an output file\0A is given.\0A\0A If the output argument is given the entire list of prime numbers\0A generated will be written as 4 byte unsigned integers to the\0A specified file.\0A\0Aupdated: Friday, April 03, 2015\0A\00"
@EXIT_SUCCESS = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Expected number of primes.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%zu\00"
@.str.4 = [39 x i8] c"Expected integer argument for primes.\0A\00"
@.str.5 = [35 x i8] c"ERROR: Failed to allocate memory.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i64
store i64 0, i64* @opterr
br label %4
4: ; preds = %6, %2
%5 = phi i1 [ true, %2 ], [ false, %6 ]
br label %6
6: ; preds = %4, %6
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %6 [
i32 -1, label %13
i32 104, label %8
i32 118, label %4
]
8: ; preds = %6
%9 = load i32, i32* @stdout
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([694 x i8], [694 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_SUCCESS
br label %60
13: ; preds = %6
%14 = load i32, i32* @optind
%15 = icmp slt i32 %14, %0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
br label %60
20: ; preds = %13
%21 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%22 = add nsw i32 %14, 1
store i32 %22, i32* @optind
%23 = sext i32 %14 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%27 = icmp eq i32 %26, 1
br i1 %27, label %31, label %28
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %28, %20
%32 = load i32, i32* @optind
%33 = icmp slt i32 %32, %0
%34 = load i64, i64* %3
br i1 %33, label %35, label %43
35: ; preds = %31
%36 = add nsw i32 %32, 1
store i32 %36, i32* @optind
%37 = sext i32 %32 to i64
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = call i64 @primes_file(i64 %34, i8* %39)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %57
43: ; preds = %31
%44 = shl i64 %34, 2
%45 = call i32* @malloc(i64 %44)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %57
50: ; preds = %43
br i1 %5, label %53, label %51
51: ; preds = %50
%52 = call i32 @primes_verbose(i64 %34, i32* %45)
br label %55
53: ; preds = %50
%54 = call i32 @primes(i64 %34, i32* %45)
br label %55
55: ; preds = %53, %51
%56 = call i32 @free(i32* %45)
br label %57
57: ; preds = %47, %55, %35
%58 = phi i32* [ %42, %35 ], [ @EXIT_FAILURE, %47 ], [ @EXIT_SUCCESS, %55 ]
%59 = load i32, i32* %58
br label %60
60: ; preds = %57, %16, %8
%61 = phi i32 [ %12, %8 ], [ %19, %16 ], [ %59, %57 ]
ret i32 %61
}