#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, ...);
void permutation(char *p, void *data) {
  unsigned long long *sum = (unsigned long long *)data;
  if (p[0] != '0') {
    static int divs[] = {2, 3, 5, 7, 11, 13, 17};
    bool is_divisible = true;
    for (int j = 1; j <= 7; j++) {
      char temp[4] = {0};
      memcpy(temp, &p[j], 3);
      unsigned int d;
      sscanf(temp, "%u", &d);
      if (d % divs[j - 1] != 0) {
        is_divisible = false;
        break;
      }
    }
    if (is_divisible) {
      unsigned long long d;
      sscanf(p, "%llu", &d);
      (*sum) += d;
    }
  }
}


x86 assembly (clang, -O0):
<permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     1222 <permutation+0xf2>
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jg     11ef <permutation+0xbf>
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x24(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
lea    -0x24(%rbp),%rdi
lea    0xe5c(%rip),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rsi
lea    0x2e7e(%rip),%rcx
xor    %edx,%edx
divl   (%rcx,%rsi,4)
cmp    $0x0,%edx
je     11dc <permutation+0xac>
movl   $0x0,-0x1c(%rbp)
jmp    11ef <permutation+0xbf>
jmp    11e1 <permutation+0xb1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1166 <permutation+0x36>
cmpl   $0x0,-0x1c(%rbp)
je     121d <permutation+0xed>
mov    -0x8(%rbp),%rdi
lea    0xdff(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    1222 <permutation+0xf2>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmpb   $0x30,(%rdi)
je     1337 <permutation+0x217>
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,0x8(%rsp)
lea    0x1(%rdi),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xea3(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
testb  $0x1,0x4(%rsp)
jne    1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x2(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xe64(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xaaaaaaab,0x4(%rsp),%eax
aa
cmp    $0x55555555,%eax
ja     1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x3(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xe1d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xcccccccd,0x4(%rsp),%eax
cc
cmp    $0x33333333,%eax
ja     1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x4(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xdd6(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xb6db6db7,0x4(%rsp),%eax
b6
cmp    $0x24924924,%eax
ja     1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x5(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xd8f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xba2e8ba3,0x4(%rsp),%eax
ba
cmp    $0x1745d174,%eax
ja     1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x6(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xd48(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xc4ec4ec5,0x4(%rsp),%eax
c4
cmp    $0x13b13b13,%eax
ja     1337 <permutation+0x217>
movl   $0x0,0x8(%rsp)
lea    0x7(%r15),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
lea    0xd05(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0xf0f0f0f1,0x4(%rsp),%eax
f0
cmp    $0xf0f0f0f,%eax
ja     1337 <permutation+0x217>
lea    0xce3(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
mov    0x8(%rsp),%rax
add    %rax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@permutation.divs = internal global [7 x i32] [i32 2, i32 3, i32 5, i32 7, i32 11, i32 13, i32 17]
@.str = [3 x i8] c"%u\00"
@.str.1 = [5 x i8] c"%llu\00"
define void @permutation(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i64*
store i64* %12, i64** %5
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 48
br i1 %17, label %18, label %56
18: ; preds = %2
store i32 1, i32* %6
store i32 1, i32* %7
br label %19
19: ; preds = %42, %18
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 7
br i1 %21, label %22, label %45
22: ; preds = %19
%23 = bitcast [4 x i8]* %8 to i8*
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i32 @memcpy(i8* %24, i8* %28, i32 3)
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, i8*, ...) @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [7 x i32], [7 x i32]* @permutation.divs, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = urem i32 %32, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %22
store i32 0, i32* %6
br label %45
41: ; preds = %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %19
45: ; preds = %40, %19
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i8*, i8** %3
%50 = call i32 (i8*, i8*, ...) @sscanf(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %10)
%51 = load i64, i64* %10
%52 = load i64*, i64** %5
%53 = load i64, i64* %52
%54 = add i64 %53, %51
store i64 %54, i64* %52
br label %55
55: ; preds = %48, %45
br label %56
56: ; preds = %55, %2
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [5 x i8] c"%llu\00"
define void @permutation(i8* %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = bitcast i8* %1 to i64*
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 48
br i1 %8, label %66, label %9
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %3
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = call i32 @memcpy(i8* %10, i8* %12, i32 3)
%14 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = and i32 %15, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %66
18: ; preds = %9
store i32 0, i32* %3
%19 = getelementptr inbounds i8, i8* %0, i64 2
%20 = call i32 @memcpy(i8* %10, i8* %19, i32 3)
%21 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%22 = load i32, i32* %4
%23 = urem i32 %22, 3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %66
25: ; preds = %18
store i32 0, i32* %3
%26 = getelementptr inbounds i8, i8* %0, i64 3
%27 = call i32 @memcpy(i8* %10, i8* %26, i32 3)
%28 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%29 = load i32, i32* %4
%30 = urem i32 %29, 5
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %66
32: ; preds = %25
store i32 0, i32* %3
%33 = getelementptr inbounds i8, i8* %0, i64 4
%34 = call i32 @memcpy(i8* %10, i8* %33, i32 3)
%35 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%36 = load i32, i32* %4
%37 = urem i32 %36, 7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %66
39: ; preds = %32
store i32 0, i32* %3
%40 = getelementptr inbounds i8, i8* %0, i64 5
%41 = call i32 @memcpy(i8* %10, i8* %40, i32 3)
%42 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%43 = load i32, i32* %4
%44 = urem i32 %43, 11
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %66
46: ; preds = %39
store i32 0, i32* %3
%47 = getelementptr inbounds i8, i8* %0, i64 6
%48 = call i32 @memcpy(i8* %10, i8* %47, i32 3)
%49 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%50 = load i32, i32* %4
%51 = urem i32 %50, 13
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %66
53: ; preds = %46
store i32 0, i32* %3
%54 = getelementptr inbounds i8, i8* %0, i64 7
%55 = call i32 @memcpy(i8* %10, i8* %54, i32 3)
%56 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%57 = load i32, i32* %4
%58 = urem i32 %57, 17
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %53
%61 = bitcast i64* %5 to i8*
%62 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%63 = load i64, i64* %5
%64 = load i64, i64* %6
%65 = add i64 %64, %63
store i64 %65, i64* %6
br label %66
66: ; preds = %9, %18, %25, %32, %39, %46, %53, %60, %2
ret void
}