#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 uint32_t;

/* Variables and functions */
int concat_ints(int *);
int /*<<< orphan*/ in(int, int *);
scalar_t__ is_pandigit(int);
int *malloc(int);
uint32_t productSum(void) {
  uint32_t i, j, product, concat, productSum;
  productSum = 0;
  uint32_t *productList;
  uint32_t index = 0;
  productList = malloc(20 * sizeof(uint32_t));
  for (i = 1; i < 2000; i++) {
    for (j = 1; j < 2000; j++) {
      product = i * j;
      if (product > 9876) {
        continue;
      }
      uint32_t tmp[4] = {i, j, product, 0};
      concat = concat_ints(tmp);
      if (is_pandigit(concat)) {
        if (!in(product, productList)) {
          productList[index++] = product;
          productSum += product;
        }
      }
    }
  }
  return productSum;
}


x86 assembly (clang, -O0):
<productSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x4(%rbp)
cmpl   $0x7d0,-0x4(%rbp)
jge    1240 <productSum+0x100>
movl   $0x1,-0x8(%rbp)
cmpl   $0x7d0,-0x8(%rbp)
jge    122d <productSum+0xed>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2694,-0xc(%rbp)
jle    11a8 <productSum+0x68>
jmp    121f <productSum+0xdf>
mov    -0x4(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <concat_ints@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <is_pandigit@plt>
cmp    $0x0,%rax
je     121a <productSum+0xda>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <in@plt>
cmp    $0x0,%eax
jne    1215 <productSum+0xd5>
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    121a <productSum+0xda>
jmp    121f <productSum+0xdf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117f <productSum+0x3f>
jmp    1232 <productSum+0xf2>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116b <productSum+0x2b>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<productSum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    $0x1,%ebx
xor    %r13d,%r13d
lea    0x10(%rsp),%r14
movl   $0x0,0xc(%rsp)
jmp    118b <productSum+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x7d0,%ebx
je     11ff <productSum+0xbf>
mov    %ebx,%ebp
mov    $0x1,%r15d
jmp    11af <productSum+0x6f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15d
add    %ebx,%ebp
cmp    $0x7d0,%r15d
je     1180 <productSum+0x40>
cmp    $0x2694,%ebp
ja     11a0 <productSum+0x60>
mov    %ebx,0x10(%rsp)
mov    %r15d,0x14(%rsp)
mov    %ebp,0x18(%rsp)
movl   $0x0,0x1c(%rsp)
mov    %r14,%rdi
call   1040 <concat_ints@plt>
mov    %eax,%edi
call   1030 <is_pandigit@plt>
test   %rax,%rax
je     11a0 <productSum+0x60>
mov    %ebp,%edi
mov    %r12,%rsi
call   1060 <in@plt>
test   %eax,%eax
jne    11a0 <productSum+0x60>
movslq %r13d,%rax
add    $0x1,%r13d
mov    %ebp,(%r12,%rax,4)
add    %ebp,0xc(%rsp)
jmp    11a0 <productSum+0x60>
mov    0xc(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @productSum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [4 x i32]
store i32 0, i32* %5
store i32 0, i32* %7
%9 = call i32* @malloc(i32 80)
store i32* %9, i32** %6
store i32 1, i32* %1
br label %10
10: ; preds = %58, %0
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 2000
br i1 %12, label %13, label %61
13: ; preds = %10
store i32 1, i32* %2
br label %14
14: ; preds = %54, %13
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 2000
br i1 %16, label %17, label %57
17: ; preds = %14
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = mul nsw i32 %18, %19
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 9876
br i1 %22, label %23, label %24
23: ; preds = %17
br label %54
24: ; preds = %17
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%26 = load i32, i32* %1
store i32 %26, i32* %25
%27 = getelementptr inbounds i32, i32* %25, i64 1
%28 = load i32, i32* %2
store i32 %28, i32* %27
%29 = getelementptr inbounds i32, i32* %27, i64 1
%30 = load i32, i32* %3
store i32 %30, i32* %29
%31 = getelementptr inbounds i32, i32* %29, i64 1
store i32 0, i32* %31
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%33 = call i32 @concat_ints(i32* %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = call i64 @is_pandigit(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %53
37: ; preds = %24
%38 = load i32, i32* %3
%39 = load i32*, i32** %6
%40 = call i32 @in(i32 %38, i32* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %52, label %42
42: ; preds = %37
%43 = load i32, i32* %3
%44 = load i32*, i32** %6
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 %43, i32* %48
%49 = load i32, i32* %3
%50 = load i32, i32* %5
%51 = add nsw i32 %50, %49
store i32 %51, i32* %5
br label %52
52: ; preds = %42, %37
br label %53
53: ; preds = %52, %24
br label %54
54: ; preds = %53, %23
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %14
57: ; preds = %14
br label %58
58: ; preds = %57
%59 = load i32, i32* %1
%60 = add nsw i32 %59, 1
store i32 %60, i32* %1
br label %10
61: ; preds = %10
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
define i32 @productSum() {
%1 = alloca [4 x i32]
%2 = tail call i32* @malloc(i32 80)
%3 = bitcast [4 x i32]* %1 to i8*
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
br label %8
8: ; preds = %0, %38
%9 = phi i32 [ 0, %0 ], [ %35, %38 ]
%10 = phi i32 [ 1, %0 ], [ %39, %38 ]
%11 = phi i32 [ 0, %0 ], [ %34, %38 ]
br label %12
12: ; preds = %8, %33
%13 = phi i32 [ %9, %8 ], [ %35, %33 ]
%14 = phi i32 [ %11, %8 ], [ %34, %33 ]
%15 = phi i32 [ 1, %8 ], [ %36, %33 ]
%16 = mul nuw nsw i32 %15, %10
%17 = icmp ugt i32 %16, 9876
br i1 %17, label %33, label %18
18: ; preds = %12
store i32 %10, i32* %4
store i32 %15, i32* %5
store i32 %16, i32* %6
store i32 0, i32* %7
%19 = call i32 @concat_ints(i32* %4)
%20 = call i64 @is_pandigit(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = call i32 @in(i32 %16, i32* %2)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = add nsw i32 %13, 1
%27 = sext i32 %13 to i64
%28 = getelementptr inbounds i32, i32* %2, i64 %27
store i32 %16, i32* %28
%29 = add nsw i32 %14, %16
br label %30
30: ; preds = %22, %25, %18
%31 = phi i32 [ %14, %22 ], [ %29, %25 ], [ %14, %18 ]
%32 = phi i32 [ %13, %22 ], [ %26, %25 ], [ %13, %18 ]
br label %33
33: ; preds = %12, %30
%34 = phi i32 [ %14, %12 ], [ %31, %30 ]
%35 = phi i32 [ %13, %12 ], [ %32, %30 ]
%36 = add nuw nsw i32 %15, 1
%37 = icmp eq i32 %36, 2000
br i1 %37, label %38, label %12
38: ; preds = %33
%39 = add nuw nsw i32 %10, 1
%40 = icmp eq i32 %39, 2000
br i1 %40, label %41, label %8
41: ; preds = %38
ret i32 %34
}