#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*/ uint8_t;
struct stat {
  size_t st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ find_numbers(int /*<<< orphan*/ *, size_t, int, int,
                                int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(int /*<<< orphan*/ *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fstat(int, struct stat *);
int getopt(int, char **, char *);
int /*<<< orphan*/ init_factorbase(int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ optarg;
size_t optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  uint8_t *data = NULL;
  size_t data_len;
  FILE *f;
  int fno;
  struct stat st;
  int res = 0;
  int opt, bits = 0;
  while ((opt = getopt(argc, argv, "b:")) != -1) {
    switch (opt) {
    case 'b':
      bits = atoi(optarg);
      break;
    default:
      fprintf(stderr, "Usage: %s [-t bitsize] file\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  f = fopen(argv[optind], "rb");
  if (f == NULL) {
    perror("Can't open file\n");
    return 1;
  }
  fno = fileno(f);
  fstat(fno, &st);
  data_len = st.st_size;
  data = (uint8_t *)malloc(data_len);
  if (data == NULL) {
    perror("Couldn't allocate memory for file");
    res = 1;
    goto exit;
  }
  if (fread(data, 1, data_len, f) != (size_t)data_len) {
    printf("couldn't read data file\n");
    res = 1;
    goto exit;
  }
  fclose(f);
  f = NULL;
  init_factorbase(bits);
  printf("Trying to find %d bits crypto numbers\n", bits);
  find_numbers(data, data_len, bits, 1, 0);
exit:
  if (f != NULL)
    fclose(f);
  if (data != NULL)
    free(data);
  return res;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdd6(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x40(%rbp)
cmp    $0xffffffff,%eax
je     1291 <main+0xa1>
mov    -0x40(%rbp),%eax
sub    $0x62,%eax
jne    1262 <main+0x72>
jmp    124c <main+0x5c>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %eax,-0x44(%rbp)
jmp    128c <main+0x9c>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd8a(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    121c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    0x2d44(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd76(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d6 <main+0xe6>
lea    0xd5e(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d0 <main+0x1e0>
mov    -0x28(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1110 <fstat@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1326 <main+0x136>
lea    0xd1f(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x3c(%rbp)
jmp    13a2 <main+0x1b2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x20(%rbp),%rax
je     1360 <main+0x170>
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x3c(%rbp)
jmp    13a2 <main+0x1b2>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x44(%rbp),%edi
call   1070 <init_factorbase@plt>
mov    -0x44(%rbp),%esi
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   10b0 <find_numbers@plt>
cmpq   $0x0,-0x28(%rbp)
je     13b6 <main+0x1c6>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     13ca <main+0x1da>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %r13d,%r13d
lea    0xde6(%rip),%r14
mov    0x2dd7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10f0 <getopt@plt>
cmp    $0x62,%eax
jne    124f <main+0x4f>
mov    (%r15),%edi
call   1100 <atoi@plt>
mov    %eax,%r13d
jmp    1230 <main+0x30>
cmp    $0xffffffff,%eax
jne    1361 <main+0x161>
mov    0x2d81(%rip),%rax
mov    (%rax),%rax
mov    0x0(%rbp,%rax,8),%rdi
lea    0xdb2(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1331 <main+0x131>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1120 <fstat@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1345 <main+0x145>
mov    %rax,%r14
mov    $0x1,%r12d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    %rbp,%rax
jne    1303 <main+0x103>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r13d,%edi
call   1080 <init_factorbase@plt>
lea    0xd78(%rip),%rdi
xor    %r12d,%r12d
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   10c0 <find_numbers@plt>
jmp    1317 <main+0x117>
lea    0xd73(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xceb(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%r12d
jmp    131f <main+0x11f>
lea    0xce8(%rip),%rdi
call   10e0 <perror@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0x1,%r12d
jmp    131f <main+0x11f>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc8e(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [3 x i8] c"b:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s [-t bitsize] file\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [17 x i8] c"Can't open file\0A\00"
@.str.4 = [34 x i8] c"Couldn't allocate memory for file\00"
@.str.5 = [25 x i8] c"couldn't read data file\0A\00"
@.str.6 = [39 x i8] c"Trying to find %d bits crypto numbers\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %11
store i32 0, i32* %13
br label %14
14: ; preds = %32, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %12
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %33
19: ; preds = %14
%20 = load i32, i32* %12
switch i32 %20, label %24 [
i32 98, label %21
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
store i32 %23, i32* %13
br label %32
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
br label %14
33: ; preds = %14
%34 = load i8**, i8*** %5
%35 = load i64, i64* @optind
%36 = getelementptr inbounds i8*, i8** %34, i64 %35
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %8
%39 = load i32*, i32** %8
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %91
43: ; preds = %33
%44 = load i32*, i32** %8
%45 = call i32 @fileno(i32* %44)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = call i32 @fstat(i32 %46, %struct.stat* %10)
%48 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%49 = load i64, i64* %48
store i64 %49, i64* %7
%50 = load i64, i64* %7
%51 = call i64 @malloc(i64 %50)
%52 = inttoptr i64 %51 to i32*
store i32* %52, i32** %6
%53 = load i32*, i32** %6
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %57
55: ; preds = %43
%56 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %11
br label %77
57: ; preds = %43
%58 = load i32*, i32** %6
%59 = load i64, i64* %7
%60 = load i32*, i32** %8
%61 = call i64 @fread(i32* %58, i32 1, i64 %59, i32* %60)
%62 = load i64, i64* %7
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %57
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %11
br label %77
66: ; preds = %57
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
store i32* null, i32** %8
%69 = load i32, i32* %13
%70 = call i32 @init_factorbase(i32 %69)
%71 = load i32, i32* %13
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = load i32*, i32** %6
%74 = load i64, i64* %7
%75 = load i32, i32* %13
%76 = call i32 @find_numbers(i32* %73, i64 %74, i32 %75, i32 1, i32 0)
br label %77
77: ; preds = %66, %64, %55
%78 = load i32*, i32** %8
%79 = icmp ne i32* %78, null
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %80, %77
%84 = load i32*, i32** %6
%85 = icmp ne i32* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32*, i32** %6
%88 = call i32 @free(i32* %87)
br label %89
89: ; preds = %86, %83
%90 = load i32, i32* %11
store i32 %90, i32* %3
br label %91
91: ; preds = %89, %41
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [3 x i8] c"b:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s [-t bitsize] file\0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [17 x i8] c"Can't open file\0A\00"
@.str.4 = [34 x i8] c"Couldn't allocate memory for file\00"
@.str.6 = [39 x i8] c"Trying to find %d bits crypto numbers\0A\00"
@str = [24 x i8] c"couldn't read data file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
br label %5
5: ; preds = %8, %2
%6 = phi i32 [ 0, %2 ], [ %10, %8 ]
%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 %11 [
i32 -1, label %17
i32 98, label %8
]
8: ; preds = %5
%9 = load i32, i32* @optarg
%10 = tail call i32 @atoi(i32 %9)
br label %5
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %5
%18 = load i64, i64* @optind
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %50
25: ; preds = %17
%26 = tail call i32 @fileno(i32* %21)
%27 = call i32 @fstat(i32 %26, %struct.stat* %3)
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i64, i64* %28
%30 = tail call i64 @malloc(i64 %29)
%31 = inttoptr i64 %30 to i32*
%32 = icmp eq i64 %30, 0
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @fclose(i32* %21)
br label %50
36: ; preds = %25
%37 = tail call i64 @fread(i32* %31, i32 1, i64 %29, i32* %21)
%38 = icmp eq i64 %37, %29
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = tail call i32 @fclose(i32* %21)
%41 = tail call i32 @init_factorbase(i32 %6)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %6)
%43 = tail call i32 @find_numbers(i32* %31, i64 %29, i32 %6, i32 1, i32 0)
br label %47
44: ; preds = %36
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%46 = tail call i32 @fclose(i32* %21)
br label %47
47: ; preds = %44, %39
%48 = phi i32 [ 0, %39 ], [ 1, %44 ]
%49 = tail call i32 @free(i32* %31)
br label %50
50: ; preds = %33, %47, %23
%51 = phi i32 [ 1, %23 ], [ %48, %47 ], [ 1, %33 ]
ret i32 %51
}