#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 */
struct pandigital_entry {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_pandigital_entry(struct pandigital_entry **, char *, int,
                                        unsigned long);
struct pandigital_entry **calloc(int, int);
unsigned long create_pandigital_hash(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ is_pandigital(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
scalar_t__ strchr(char *, int /*<<< orphan*/);
int strlen(char *);
float timeit();
float total_pandigital_products(struct pandigital_entry **);
int main(int argc, char *argv[]) {
  float start = timeit();
  struct pandigital_entry **table = calloc(sizeof *table * 7000, sizeof *table);
  char *prime_str = malloc(sizeof(char) * 13 + 1);
  for (int i = 2; i < 100; i++) {
    for (int j = 100; j < 5000; j++) {
      int product = i * j;
      snprintf(prime_str, 13, "%d%d%d", product, i, j);
      if (strlen(prime_str) != 9 || strchr(prime_str, '0'))
        continue;
      if (is_pandigital(prime_str)) {
        unsigned long pandigital_hash = create_pandigital_hash(prime_str);
        add_pandigital_entry(table, prime_str, product, pandigital_hash);
      }
    }
  }
  float stop = timeit();
  printf("Answer: %ld\n", total_pandigital_products(table));
  printf("Time: %f\n", stop - start);
  free(table);
  free(prime_str);
  return 0;
}


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)
mov    $0x0,%al
call   10c0 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
mov    $0xdac0,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0xe,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
cmpl   $0x64,-0x2c(%rbp)
jge    12db <main+0x11b>
movl   $0x64,-0x30(%rbp)
cmpl   $0x1388,-0x30(%rbp)
jge    12c8 <main+0x108>
mov    -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    $0xd,%esi
lea    0xdb3(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jne    127c <main+0xbc>
mov    -0x28(%rbp),%rdi
mov    $0x30,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1281 <main+0xc1>
jmp    12ba <main+0xfa>
mov    -0x28(%rbp),%rdi
call   10d0 <is_pandigital@plt>
cmp    $0x0,%rax
je     12b5 <main+0xf5>
mov    -0x28(%rbp),%rdi
call   1050 <create_pandigital_hash@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x40(%rbp),%rcx
call   10e0 <add_pandigital_entry@plt>
jmp    12ba <main+0xfa>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    121b <main+0x5b>
jmp    12cd <main+0x10d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120a <main+0x4a>
mov    $0x0,%al
call   10c0 <timeit@plt>
movss  %xmm0,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <total_pandigital_products@plt>
lea    0xd10(%rip),%rdi
call   1070 <printf@plt>
movss  -0x44(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xd07(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   10c0 <timeit@plt>
movss  %xmm0,0xc(%rsp)
mov    $0xdac0,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,0x10(%rsp)
mov    $0xe,%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    $0x2,%r12d
mov    $0xc8,%r14d
lea    0xdf1(%rip),%r15
jmp    1232 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
add    $0x64,%r14d
cmp    $0x64,%r12d
je     12ae <main+0xee>
mov    $0x64,%ebp
mov    %r14d,%ebx
jmp    124e <main+0x8e>
nopl   0x0(%rax)
add    $0x1,%ebp
add    %r12d,%ebx
cmp    $0x1388,%ebp
je     1220 <main+0x60>
mov    %r13,%rdi
mov    $0xd,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
call   1080 <snprintf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jne    1240 <main+0x80>
mov    %r13,%rdi
mov    $0x30,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    1240 <main+0x80>
mov    %r13,%rdi
call   10d0 <is_pandigital@plt>
test   %rax,%rax
je     1240 <main+0x80>
mov    %r13,%rdi
call   1050 <create_pandigital_hash@plt>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %rax,%rcx
call   10e0 <add_pandigital_entry@plt>
jmp    1240 <main+0x80>
xor    %eax,%eax
call   10c0 <timeit@plt>
movss  %xmm0,0x8(%rsp)
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <total_pandigital_products@plt>
lea    0xd38(%rip),%rdi
call   1070 <printf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
lea    0xd2d(%rip),%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pandigital_entry = type { i32 }
@.str = [7 x i8] c"%d%d%d\00"
@.str.1 = [13 x i8] c"Answer: %ld\0A\00"
@.str.2 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca %struct.pandigital_entry**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call float (...) @timeit()
store float %14, float* %6
%15 = call %struct.pandigital_entry** @calloc(i32 56000, i32 8)
store %struct.pandigital_entry** %15, %struct.pandigital_entry*** %7
%16 = call i8* @malloc(i32 14)
store i8* %16, i8** %8
store i32 2, i32* %9
br label %17
17: ; preds = %58, %2
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %61
20: ; preds = %17
store i32 100, i32* %10
br label %21
21: ; preds = %54, %20
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 5000
br i1 %23, label %24, label %57
24: ; preds = %21
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = mul nsw i32 %25, %26
store i32 %27, i32* %11
%28 = load i8*, i8** %8
%29 = load i32, i32* %11
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 @snprintf(i8* %28, i32 13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i32 %31)
%33 = load i8*, i8** %8
%34 = call i32 @strlen(i8* %33)
%35 = icmp ne i32 %34, 9
br i1 %35, label %40, label %36
36: ; preds = %24
%37 = load i8*, i8** %8
%38 = call i64 @strchr(i8* %37, i32 48)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36, %24
br label %54
41: ; preds = %36
%42 = load i8*, i8** %8
%43 = call i64 @is_pandigital(i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = call i64 @create_pandigital_hash(i8* %46)
store i64 %47, i64* %12
%48 = load %struct.pandigital_entry**, %struct.pandigital_entry*** %7
%49 = load i8*, i8** %8
%50 = load i32, i32* %11
%51 = load i64, i64* %12
%52 = call i32 @add_pandigital_entry(%struct.pandigital_entry** %48, i8* %49, i32 %50, i64 %51)
br label %53
53: ; preds = %45, %41
br label %54
54: ; preds = %53, %40
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %21
57: ; preds = %21
br label %58
58: ; preds = %57
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %17
61: ; preds = %17
%62 = call float (...) @timeit()
store float %62, float* %13
%63 = load %struct.pandigital_entry**, %struct.pandigital_entry*** %7
%64 = call float @total_pandigital_products(%struct.pandigital_entry** %63)
%65 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), float %64)
%66 = load float, float* %13
%67 = load float, float* %6
%68 = fsub float %66, %67
%69 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), float %68)
%70 = load %struct.pandigital_entry**, %struct.pandigital_entry*** %7
%71 = bitcast %struct.pandigital_entry** %70 to i8*
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %8
%74 = call i32 @free(i8* %73)
ret i32 0
}

LLVM IR (-O2):
%struct.pandigital_entry = type { i32 }
@.str = [7 x i8] c"%d%d%d\00"
@.str.1 = [13 x i8] c"Answer: %ld\0A\00"
@.str.2 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
%4 = tail call %struct.pandigital_entry** @calloc(i32 56000, i32 8)
%5 = tail call dereferenceable_or_null(14) i8* @malloc(i32 14)
br label %6
6: ; preds = %2, %17
%7 = phi i32 [ 2, %2 ], [ %18, %17 ]
br label %20
8: ; preds = %17
%9 = tail call float (...) @timeit()
%10 = tail call float @total_pandigital_products(%struct.pandigital_entry** %4)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), float %10)
%12 = fsub float %9, %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), float %12)
%14 = bitcast %struct.pandigital_entry** %4 to i8*
%15 = tail call i32 @free(i8* %14)
%16 = tail call i32 @free(i8* %5)
ret i32 0
17: ; preds = %35
%18 = add nuw nsw i32 %7, 1
%19 = icmp eq i32 %18, 100
br i1 %19, label %8, label %6
20: ; preds = %6, %35
%21 = phi i32 [ 100, %6 ], [ %36, %35 ]
%22 = mul nuw nsw i32 %21, %7
%23 = tail call i32 @snprintf(i8* %5, i32 13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %7, i32 %21)
%24 = tail call i32 @strlen(i8* %5)
%25 = icmp eq i32 %24, 9
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = tail call i64 @strchr(i8* %5, i32 48)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = tail call i64 @is_pandigital(i8* %5)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = tail call i64 @create_pandigital_hash(i8* %5)
%34 = tail call i32 @add_pandigital_entry(%struct.pandigital_entry** %4, i8* %5, i32 %22, i64 %33)
br label %35
35: ; preds = %29, %32, %20, %26
%36 = add nuw nsw i32 %21, 1
%37 = icmp eq i32 %36, 5000
br i1 %37, label %17, label %20
}