#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*/ free_part_sum_bitarrays();
int /*<<< orphan*/ free_sum_bitarray();
int /*<<< orphan*/ init_part_sum_bitarrays();
int /*<<< orphan*/ init_sum_bitarray(int);
int /*<<< orphan*/ precalculate_bit0_bitflip_bitarrays(unsigned int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int main(int argc, char *argv[]) {
  unsigned int bitflip_in;
  int sum_a0 = 0;
  printf("Create tables required by hardnested attack.\n");
  printf("Expect a runtime in the range of days or weeks.\n");
  printf("Single thread only. If you want to use several threads, start it "
         "multiple times :-)\n\n");
  if (argc != 2 && argc != 3) {
    printf(" syntax: %s <bitflip property> [<Sum_a0>]\n\n", argv[0]);
    printf(" example: %s 1f\n", argv[0]);
    return 1;
  }
  sscanf(argv[1], "%x", &bitflip_in);
  if (bitflip_in > 255) {
    printf("Bitflip property must be less than or equal to 0xff\n\n");
    return 1;
  }
  if (argc == 3) {
    sscanf(argv[2], "%d", &sum_a0);
  }
  switch (sum_a0) {
  case 0:
  case 32:
  case 56:
  case 64:
  case 80:
  case 96:
  case 104:
  case 112:
  case 120:
  case 128:
  case 136:
  case 144:
  case 152:
  case 160:
  case 176:
  case 192:
  case 200:
  case 224:
  case 256:
    break;
  default:
    sum_a0 = -1;
  }
  printf("Calculating for bitflip = %02x, sum_a0 = %d\n", bitflip_in, sum_a0);
  init_part_sum_bitarrays();
  init_sum_bitarray(sum_a0);
  precalculate_bit0_bitflip_bitarrays(bitflip_in, sum_a0);
  free_sum_bitarray();
  free_part_sum_bitarrays();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     1201 <main+0x91>
cmpl   $0x3,-0x8(%rbp)
je     1201 <main+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    140e <main+0x29e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xee2(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmpl   $0xff,-0x14(%rbp)
jbe    1242 <main+0xd2>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    140e <main+0x29e>
cmpl   $0x3,-0x8(%rbp)
jne    1266 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xed0(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     13bf <main+0x24f>
jmp    1279 <main+0x109>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
je     13bf <main+0x24f>
jmp    128a <main+0x11a>
mov    -0x1c(%rbp),%eax
sub    $0x38,%eax
je     13bf <main+0x24f>
jmp    129b <main+0x12b>
mov    -0x1c(%rbp),%eax
sub    $0x40,%eax
je     13bf <main+0x24f>
jmp    12ac <main+0x13c>
mov    -0x1c(%rbp),%eax
sub    $0x50,%eax
je     13bf <main+0x24f>
jmp    12bd <main+0x14d>
mov    -0x1c(%rbp),%eax
sub    $0x60,%eax
je     13bf <main+0x24f>
jmp    12ce <main+0x15e>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
je     13bf <main+0x24f>
jmp    12df <main+0x16f>
mov    -0x1c(%rbp),%eax
sub    $0x70,%eax
je     13bf <main+0x24f>
jmp    12f0 <main+0x180>
mov    -0x1c(%rbp),%eax
sub    $0x78,%eax
je     13bf <main+0x24f>
jmp    1301 <main+0x191>
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
je     13bf <main+0x24f>
jmp    1314 <main+0x1a4>
mov    -0x1c(%rbp),%eax
sub    $0x88,%eax
je     13bf <main+0x24f>
jmp    1327 <main+0x1b7>
mov    -0x1c(%rbp),%eax
sub    $0x90,%eax
je     13bf <main+0x24f>
jmp    133a <main+0x1ca>
mov    -0x1c(%rbp),%eax
sub    $0x98,%eax
je     13bf <main+0x24f>
jmp    134d <main+0x1dd>
mov    -0x1c(%rbp),%eax
sub    $0xa0,%eax
je     13bf <main+0x24f>
jmp    1360 <main+0x1f0>
mov    -0x1c(%rbp),%eax
sub    $0xb0,%eax
je     13bf <main+0x24f>
jmp    1373 <main+0x203>
mov    -0x1c(%rbp),%eax
sub    $0xc0,%eax
je     13bf <main+0x24f>
jmp    1386 <main+0x216>
mov    -0x1c(%rbp),%eax
sub    $0xc8,%eax
je     13bf <main+0x24f>
jmp    1399 <main+0x229>
mov    -0x1c(%rbp),%eax
sub    $0xe0,%eax
je     13bf <main+0x24f>
jmp    13ac <main+0x23c>
mov    -0x1c(%rbp),%eax
sub    $0x100,%eax
jne    13c4 <main+0x254>
jmp    13bf <main+0x24f>
jmp    13cb <main+0x25b>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <init_part_sum_bitarrays@plt>
mov    -0x18(%rbp),%edi
call   1090 <init_sum_bitarray@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <precalculate_bit0_bitflip_bitarrays@plt>
mov    $0x0,%al
call   1070 <free_sum_bitarray@plt>
mov    $0x0,%al
call   1060 <free_part_sum_bitarrays@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x8(%rsp)
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf19(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11fd <main+0x7d>
mov    0x8(%rbx),%rdi
lea    0xe6f(%rip),%rsi
xor    %r14d,%r14d
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmpl   $0x100,0xc(%rsp)
jb     1226 <main+0xa6>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    12a4 <main+0x124>
mov    (%rbx),%rsi
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    12a4 <main+0x124>
cmp    $0x3,%ebp
jne    1247 <main+0xc7>
mov    0x10(%rbx),%rdi
lea    0xe0a(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    0x8(%rsp),%r14d
mov    %r14d,%eax
rol    $0x1d,%eax
cmp    $0x20,%eax
ja     12af <main+0x12f>
movabs $0x1135ff591,%rcx
bt     %rax,%rcx
jae    12af <main+0x12f>
mov    0xc(%rsp),%esi
lea    0xdd6(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <init_part_sum_bitarrays@plt>
mov    0x8(%rsp),%edi
call   10a0 <init_sum_bitarray@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1050 <precalculate_bit0_bitflip_bitarrays@plt>
xor    %eax,%eax
call   1080 <free_sum_bitarray@plt>
xor    %eax,%eax
call   1070 <free_part_sum_bitarrays@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movl   $0xffffffff,0x8(%rsp)
ff
mov    $0xffffffff,%r14d
jmp    1262 <main+0xe2>

LLVM IR (-O0):
@.str = [46 x i8] c"Create tables required by hardnested attack.\0A\00"
@.str.1 = [49 x i8] c"Expect a runtime in the range of days or weeks.\0A\00"
@.str.2 = [86 x i8] c"Single thread only. If you want to use several threads, start it multiple times :-)\0A\0A\00"
@.str.3 = [44 x i8] c" syntax: %s <bitflip property> [<Sum_a0>]\0A\0A\00"
@.str.4 = [17 x i8] c" example: %s 1f\0A\00"
@.str.5 = [3 x i8] c"%x\00"
@.str.6 = [54 x i8] c"Bitflip property must be less than or equal to 0xff\0A\0A\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [45 x i8] c"Calculating for bitflip = %02x, sum_a0 = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %58
25: ; preds = %13, %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%30 = load i32, i32* %6
%31 = icmp ugt i32 %30, 255
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %58
34: ; preds = %25
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i8*, i8*, ...) @sscanf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %7)
br label %42
42: ; preds = %37, %34
%43 = load i32, i32* %7
switch i32 %43, label %45 [
i32 0, label %44
i32 32, label %44
i32 56, label %44
i32 64, label %44
i32 80, label %44
i32 96, label %44
i32 104, label %44
i32 112, label %44
i32 120, label %44
i32 128, label %44
i32 136, label %44
i32 144, label %44
i32 152, label %44
i32 160, label %44
i32 176, label %44
i32 192, label %44
i32 200, label %44
i32 224, label %44
i32 256, label %44
]
44: ; preds = %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42, %42
br label %46
45: ; preds = %42
store i32 -1, i32* %7
br label %46
46: ; preds = %45, %44
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i32 %47, i32 %48)
%50 = call i32 (...) @init_part_sum_bitarrays()
%51 = load i32, i32* %7
%52 = call i32 @init_sum_bitarray(i32 %51)
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = call i32 @precalculate_bit0_bitflip_bitarrays(i32 %53, i32 %54)
%56 = call i32 (...) @free_sum_bitarray()
%57 = call i32 (...) @free_part_sum_bitarrays()
store i32 0, i32* %3
br label %58
58: ; preds = %46, %32, %16
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str.3 = [44 x i8] c" syntax: %s <bitflip property> [<Sum_a0>]\0A\0A\00"
@.str.4 = [17 x i8] c" example: %s 1f\0A\00"
@.str.5 = [3 x i8] c"%x\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [45 x i8] c"Calculating for bitflip = %02x, sum_a0 = %d\0A\00"
@str = [45 x i8] c"Create tables required by hardnested attack.\00"
@str.9 = [48 x i8] c"Expect a runtime in the range of days or weeks.\00"
@str.10 = [85 x i8] c"Single thread only. If you want to use several threads, start it multiple times :-)\0A\00"
@str.11 = [53 x i8] c"Bitflip property must be less than or equal to 0xff\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.10, i64 0, i64 0))
%10 = and i32 %0, -2
%11 = icmp eq i32 %10, 2
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %48
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
%22 = icmp ugt i32 %21, 255
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.11, i64 0, i64 0))
br label %48
25: ; preds = %17
%26 = icmp eq i32 %0, 3
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 (i8*, i8*, ...) @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %4)
%31 = load i32, i32* %4
br label %32
32: ; preds = %27, %25
%33 = phi i32 [ %31, %27 ], [ 0, %25 ]
%34 = call i32 @llvm.fshl.i32(i32 %33, i32 %33, i32 29)
switch i32 %34, label %35 [
i32 0, label %36
i32 4, label %36
i32 7, label %36
i32 8, label %36
i32 10, label %36
i32 12, label %36
i32 13, label %36
i32 14, label %36
i32 15, label %36
i32 16, label %36
i32 17, label %36
i32 18, label %36
i32 19, label %36
i32 20, label %36
i32 22, label %36
i32 24, label %36
i32 25, label %36
i32 28, label %36
i32 32, label %36
]
35: ; preds = %32
store i32 -1, i32* %4
br label %36
36: ; preds = %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %32, %35
%37 = phi i32 [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ %33, %32 ], [ -1, %35 ]
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i32 %38, i32 %37)
%40 = call i32 (...) @init_part_sum_bitarrays()
%41 = load i32, i32* %4
%42 = call i32 @init_sum_bitarray(i32 %41)
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = call i32 @precalculate_bit0_bitflip_bitarrays(i32 %43, i32 %44)
%46 = call i32 (...) @free_sum_bitarray()
%47 = call i32 (...) @free_part_sum_bitarrays()
br label %48
48: ; preds = %36, %23, %12
%49 = phi i32 [ 1, %12 ], [ 1, %23 ], [ 0, %36 ]
ret i32 %49
}