#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 ilen(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ same_digits(int, int);
int main(void) {
  const int pow10t[] = {1,      10,      100,      1000,     10000,
                        100000, 1000000, 10000000, 100000000};
  int n = 125874;
  int x = 0;
  while (x < 6) {
    int len = ilen(n);
    if (n / (len >= 3 ? pow10t[len - 3] : 1) > 1000 / 6)
      n = pow10t[len + 1];
    else
      ++n;
    int k;
    x = 0;
    do {
      k = ++x * n;
    } while (same_digits(n, k));
  }
  printf("%d\n", n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x1ebb2,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x6,-0x38(%rbp)
jge    121a <main+0xda>
mov    -0x34(%rbp),%edi
call   1040 <ilen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jl     11ab <main+0x6b>
mov    -0x3c(%rbp),%eax
sub    $0x3,%eax
cltq
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x48(%rbp)
jmp    11b8 <main+0x78>
mov    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11b8 <main+0x78>
mov    -0x44(%rbp),%eax
mov    -0x48(%rbp),%ecx
cltd
idiv   %ecx
cmp    $0xa6,%eax
jle    11e0 <main+0xa0>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
jmp    11e9 <main+0xa9>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
imul   -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1060 <same_digits@plt>
cmp    $0x0,%rax
jne    11f0 <main+0xb0>
jmp    1172 <main+0x32>
mov    -0x34(%rbp),%esi
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1ebb2,%r15d
lea    0xebc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
call   1040 <ilen@plt>
mov    %eax,%ecx
mov    $0x1,%esi
cmp    $0x3,%eax
jl     116b <main+0x3b>
lea    -0x3(%rcx),%eax
mov    (%r14,%rax,4),%esi
mov    %r15d,%eax
cltd
idiv   %esi
cmp    $0xa7,%eax
jl     1190 <main+0x60>
movslq %ecx,%rax
mov    0x4(%r14,%rax,4),%r15d
jmp    1194 <main+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15d
mov    $0xffffffff,%ebx
mov    %r15d,%ebp
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %ebp,%esi
call   1050 <same_digits@plt>
add    $0x1,%ebx
add    %r15d,%ebp
test   %rax,%rax
jne    11a0 <main+0x70>
cmp    $0x4,%ebx
jbe    1150 <main+0x20>
lea    0xe63(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.pow10t = [9 x i32] [i32 1, i32 10, i32 100, i32 1000, i32 10000, i32 100000, i32 1000000, i32 10000000, i32 100000000]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [9 x i32]* %2 to i8*
store i32 125874, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %48, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 6
br i1 %10, label %11, label %49
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @ilen(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
br label %24
23: ; preds = %11
br label %24
24: ; preds = %23, %17
%25 = phi i32 [ %22, %17 ], [ 1, %23 ]
%26 = sdiv i32 %14, %25
%27 = icmp sgt i32 %26, 166
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
store i32 %33, i32* %3
br label %37
34: ; preds = %24
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %37
37: ; preds = %34, %28
store i32 0, i32* %4
br label %38
38: ; preds = %43, %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
%41 = load i32, i32* %3
%42 = mul nsw i32 %40, %41
store i32 %42, i32* %6
br label %43
43: ; preds = %38
%44 = load i32, i32* %3
%45 = load i32, i32* %6
%46 = call i64 @same_digits(i32 %44, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %38, label %48
48: ; preds = %43
br label %8
49: ; preds = %8
%50 = load i32, i32* %3
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %50)
ret i32 0
}

LLVM IR (-O2):
@__const.main.pow10t = [9 x i32] [i32 1, i32 10, i32 100, i32 1000, i32 10000, i32 100000, i32 1000000, i32 10000000, i32 100000000]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
br label %3
1: ; preds = %25
%2 = icmp ult i32 %26, 5
br i1 %2, label %3, label %31
3: ; preds = %0, %1
%4 = phi i32 [ 125874, %0 ], [ %24, %1 ]
%5 = tail call i32 @ilen(i32 %4)
%6 = icmp sgt i32 %5, 2
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = add nsw i32 %5, -3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [9 x i32], [9 x i32]* @__const.main.pow10t, i64 0, i64 %9
%11 = load i32, i32* %10
br label %12
12: ; preds = %3, %7
%13 = phi i32 [ %11, %7 ], [ 1, %3 ]
%14 = sdiv i32 %4, %13
%15 = icmp sgt i32 %14, 166
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = add nsw i32 %5, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [9 x i32], [9 x i32]* @__const.main.pow10t, i64 0, i64 %18
%20 = load i32, i32* %19
br label %23
21: ; preds = %12
%22 = add nsw i32 %4, 1
br label %23
23: ; preds = %21, %16
%24 = phi i32 [ %20, %16 ], [ %22, %21 ]
br label %25
25: ; preds = %25, %23
%26 = phi i32 [ 0, %23 ], [ %27, %25 ]
%27 = add nuw nsw i32 %26, 1
%28 = mul nsw i32 %27, %24
%29 = tail call i64 @same_digits(i32 %24, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %1, label %25
31: ; preds = %1
%32 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}