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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int gmp_fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_out_raw(int /*<<< orphan*/ *, int /*<<< orphan*/);
double now();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void prep_hex_input(char *infile, char *outfile) {
  double start = now();
  fprintf(stderr, "preprocessing input from %s\n", infile);
  FILE *in = fopen(infile, "r");
  assert(in);
  FILE *out = fopen(outfile, "wb");
  assert(out);
  int count = 0;
  fwrite(&count, sizeof(count), 1, out);
  mpz_t x;
  mpz_init(x);
  for (;;) {
    int res = gmp_fscanf(in, "%Zx", x);
    if (res == EOF)
      break;
    if (res != 1) {
      fprintf(stderr, "invalid input\n");
      exit(1);
    }
    mpz_out_raw(out, x);
    count++;
  }
  fclose(in);
  rewind(out);
  fwrite(&count, sizeof(count), 1, out);
  fclose(out);
  fprintf(stderr, "preprocessing %d elements took %0.3fs\n", count,
          now() - start);
}


x86 assembly (clang, -O0):
<prep_hex_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <now@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <assert@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0x30(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xdcd(%rip),%rsi
call   1040 <gmp_fscanf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
jne    1274 <prep_hex_input+0xc4>
jmp    12b9 <prep_hex_input+0x109>
cmpl   $0x1,-0x34(%rbp)
je     129f <prep_hex_input+0xef>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10a0 <mpz_out_raw@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1247 <prep_hex_input+0x97>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <now@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
subsd  -0x18(%rbp),%xmm0
lea    0xd1f(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prep_hex_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   10b0 <now@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2e00(%rip),%r12
mov    (%r12),%edi
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <assert@plt>
lea    0xe11(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <assert@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
call   1060 <mpz_init@plt>
mov    0xc(%rsp),%ebp
lea    0xdd2(%rip),%rsi
mov    %r14,%rdi
call   1040 <gmp_fscanf@plt>
mov    0x2d89(%rip),%r13
cmp    0x0(%r13),%eax
je     1295 <prep_hex_input+0xe5>
lea    0xdb6(%rip),%r15
nopl   0x0(%rax)
cmp    $0x1,%eax
jne    12fd <prep_hex_input+0x14d>
mov    %rbx,%rdi
call   10a0 <mpz_out_raw@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <gmp_fscanf@plt>
cmp    0x0(%r13),%eax
jne    1270 <prep_hex_input+0xc0>
mov    %ebp,0xc(%rsp)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%r12),%ebx
mov    0xc(%rsp),%ebp
xor    %eax,%eax
call   10b0 <now@plt>
subsd  0x10(%rsp),%xmm0
lea    0xd51(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"preprocessing input from %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [4 x i8] c"%Zx\00"
@EOF = global i32 0
@.str.4 = [15 x i8] c"invalid input\0A\00"
@.str.5 = [39 x i8] c"preprocessing %d elements took %0.3fs\0A\00"
define void @prep_hex_input(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = call double (...) @now()
store double %11, double* %5
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = call i32 @assert(i32* %17)
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = call i32 @assert(i32* %21)
store i32 0, i32* %8
%23 = load i32*, i32** %7
%24 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %23)
%25 = load i32, i32* %9
%26 = call i32 @mpz_init(i32 %25)
br label %27
27: ; preds = %42, %2
%28 = load i32*, i32** %6
%29 = load i32, i32* %9
%30 = call i32 @gmp_fscanf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %27
br label %48
35: ; preds = %27
%36 = load i32, i32* %10
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
%43 = load i32*, i32** %7
%44 = load i32, i32* %9
%45 = call i32 @mpz_out_raw(i32* %43, i32 %44)
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %27
48: ; preds = %34
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32 @rewind(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %53)
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* @stderr
%58 = load i32, i32* %8
%59 = call double (...) @now()
%60 = load double, double* %5
%61 = fsub double %59, %60
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %58, double %61)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"preprocessing input from %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [4 x i8] c"%Zx\00"
@EOF = global i32 0
@.str.4 = [15 x i8] c"invalid input\0A\00"
@.str.5 = [39 x i8] c"preprocessing %d elements took %0.3fs\0A\00"
define void @prep_hex_input(i8* %0, i8* nocapture %1) {
%3 = alloca i32
%4 = tail call double (...) @now()
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @assert(i32* %7)
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @assert(i32* %9)
%11 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%12 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %9)
%13 = tail call i32 @mpz_init(i32 undef)
%14 = load i32, i32* %3
%15 = tail call i32 @gmp_fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 undef)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %32, label %18
18: ; preds = %2, %26
%19 = phi i32 [ %29, %26 ], [ %15, %2 ]
%20 = phi i32 [ %28, %26 ], [ %14, %2 ]
%21 = icmp eq i32 %19, 1
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = tail call i32 @mpz_out_raw(i32* %9, i32 undef)
%28 = add nsw i32 %20, 1
%29 = tail call i32 @gmp_fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 undef)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %18
32: ; preds = %26, %2
%33 = phi i32 [ %14, %2 ], [ %28, %26 ]
store i32 %33, i32* %3
%34 = tail call i32 @fclose(i32* %7)
%35 = tail call i32 @rewind(i32* %9)
%36 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %9)
%37 = tail call i32 @fclose(i32* %9)
%38 = load i32, i32* @stderr
%39 = load i32, i32* %3
%40 = tail call double (...) @now()
%41 = fsub double %40, %4
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %39, double %41)
ret void
}