#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 min(int, int);
int min_divisible_by(int x) {
  if (x % 4 == 0)
    return 4;
  if (x % 6 == 0)
    return x <= 18 ? 6 : min(6, min_divisible_by(x / 6));
  if (x % 9 == 0)
    return x <= 27 ? 9 : min(9, min_divisible_by(x / 9));
  if (x % 2 == 0)
    return min(x / 2, min_divisible_by(x / 2));
  if (x % 3 == 0)
    return min(x / 3, min_divisible_by(x / 3));
  for (int i = 4; i <= 46340 && i * i <= x; i++) {
    if (x % i == 0)
      return i;
  }
  return x;
}


x86 assembly (clang, -O0):
<min_divisible_by>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    114b <min_divisible_by+0x2b>
movl   $0x4,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
mov    -0x8(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a2 <min_divisible_by+0x82>
cmpl   $0x12,-0x8(%rbp)
jg     1176 <min_divisible_by+0x56>
mov    $0x6,%eax
mov    %eax,-0x10(%rbp)
jmp    1197 <min_divisible_by+0x77>
mov    -0x8(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <min_divisible_by@plt>
mov    %eax,%esi
mov    $0x6,%edi
call   1030 <min@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
mov    -0x8(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11f9 <min_divisible_by+0xd9>
cmpl   $0x1b,-0x8(%rbp)
jg     11cd <min_divisible_by+0xad>
mov    $0x9,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <min_divisible_by+0xce>
mov    -0x8(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <min_divisible_by@plt>
mov    %eax,%esi
mov    $0x9,%edi
call   1030 <min@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    123f <min_divisible_by+0x11f>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <min_divisible_by@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1030 <min@plt>
mov    %eax,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1285 <min_divisible_by+0x165>
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <min_divisible_by@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1030 <min@plt>
mov    %eax,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
movl   $0x4,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0xb504,-0xc(%rbp)
mov    %al,-0x1d(%rbp)
jg     12ae <min_divisible_by+0x18e>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setle  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    12be <min_divisible_by+0x19e>
jmp    12ec <min_divisible_by+0x1cc>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    12d9 <min_divisible_by+0x1b9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f2 <min_divisible_by+0x1d2>
jmp    12de <min_divisible_by+0x1be>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    128c <min_divisible_by+0x16c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<min_divisible_by>:
push   %rbx
test   $0x3,%dil
je     1163 <min_divisible_by+0x43>
imul   $0xaaaaaaab,%edi,%eax
add    $0x2aaaaaaa,%eax
mov    %eax,%ecx
ror    %ecx
cmp    $0x2aaaaaaa,%ecx
jbe    116a <min_divisible_by+0x4a>
imul   $0x38e38e39,%edi,%ecx
add    $0xe38e38e,%ecx
cmp    $0x1c71c71c,%ecx
jbe    118a <min_divisible_by+0x6a>
test   $0x1,%dil
jne    11a8 <min_divisible_by+0x88>
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
jmp    11d1 <min_divisible_by+0xb1>
mov    $0x4,%ecx
jmp    11b6 <min_divisible_by+0x96>
mov    $0x6,%ecx
cmp    $0x13,%edi
jl     11b6 <min_divisible_by+0x96>
mov    %edi,%ecx
mov    $0xaaaaaaab,%eax
imul   %rcx,%rax
shr    $0x22,%rax
mov    $0x6,%ebx
jmp    11d3 <min_divisible_by+0xb3>
mov    $0x9,%ecx
cmp    $0x1c,%edi
jl     11b6 <min_divisible_by+0x96>
mov    %edi,%eax
imul   $0x38e38e39,%rax,%rax
shr    $0x21,%rax
mov    $0x9,%ebx
jmp    11d3 <min_divisible_by+0xb3>
cmp    $0x55555555,%eax
jb     11ba <min_divisible_by+0x9a>
cmp    $0x10,%edi
jge    11e4 <min_divisible_by+0xc4>
mov    %edi,%ecx
mov    %ecx,%eax
pop    %rbx
ret
movslq %edi,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <min_divisible_by@plt>
mov    %ebx,%edi
mov    %eax,%esi
pop    %rbx
jmp    1030 <min@plt>
mov    $0x4,%ecx
nopl   0x0(%rax)
mov    %edi,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     11b6 <min_divisible_by+0x96>
cmp    $0xb503,%ecx
ja     11b4 <min_divisible_by+0x94>
add    $0x1,%ecx
mov    %ecx,%eax
imul   %ecx,%eax
cmp    %edi,%eax
jle    11f0 <min_divisible_by+0xd0>
jmp    11b4 <min_divisible_by+0x94>

LLVM IR (-O0):
define i32 @min_divisible_by(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = srem i32 %5, 4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 4, i32* %2
br label %86
9: ; preds = %1
%10 = load i32, i32* %3
%11 = srem i32 %10, 6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 18
br i1 %15, label %16, label %17
16: ; preds = %13
br label %22
17: ; preds = %13
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 6
%20 = call i32 @min_divisible_by(i32 %19)
%21 = call i32 @min(i32 6, i32 %20)
br label %22
22: ; preds = %17, %16
%23 = phi i32 [ 6, %16 ], [ %21, %17 ]
store i32 %23, i32* %2
br label %86
24: ; preds = %9
%25 = load i32, i32* %3
%26 = srem i32 %25, 9
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp sle i32 %29, 27
br i1 %30, label %31, label %32
31: ; preds = %28
br label %37
32: ; preds = %28
%33 = load i32, i32* %3
%34 = sdiv i32 %33, 9
%35 = call i32 @min_divisible_by(i32 %34)
%36 = call i32 @min(i32 9, i32 %35)
br label %37
37: ; preds = %32, %31
%38 = phi i32 [ 9, %31 ], [ %36, %32 ]
store i32 %38, i32* %2
br label %86
39: ; preds = %24
%40 = load i32, i32* %3
%41 = srem i32 %40, 2
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* %3
%45 = sdiv i32 %44, 2
%46 = load i32, i32* %3
%47 = sdiv i32 %46, 2
%48 = call i32 @min_divisible_by(i32 %47)
%49 = call i32 @min(i32 %45, i32 %48)
store i32 %49, i32* %2
br label %86
50: ; preds = %39
%51 = load i32, i32* %3
%52 = srem i32 %51, 3
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %50
%55 = load i32, i32* %3
%56 = sdiv i32 %55, 3
%57 = load i32, i32* %3
%58 = sdiv i32 %57, 3
%59 = call i32 @min_divisible_by(i32 %58)
%60 = call i32 @min(i32 %56, i32 %59)
store i32 %60, i32* %2
br label %86
61: ; preds = %50
store i32 4, i32* %4
br label %62
62: ; preds = %81, %61
%63 = load i32, i32* %4
%64 = icmp sle i32 %63, 46340
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* %4
%67 = load i32, i32* %4
%68 = mul nsw i32 %66, %67
%69 = load i32, i32* %3
%70 = icmp sle i32 %68, %69
br label %71
71: ; preds = %65, %62
%72 = phi i1 [ false, %62 ], [ %70, %65 ]
br i1 %72, label %73, label %84
73: ; preds = %71
%74 = load i32, i32* %3
%75 = load i32, i32* %4
%76 = srem i32 %74, %75
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = load i32, i32* %4
store i32 %79, i32* %2
br label %86
80: ; preds = %73
br label %81
81: ; preds = %80
%82 = load i32, i32* %4
%83 = add nsw i32 %82, 1
store i32 %83, i32* %4
br label %62
84: ; preds = %71
%85 = load i32, i32* %3
store i32 %85, i32* %2
br label %86
86: ; preds = %84, %78, %54, %43, %37, %22, %8
%87 = load i32, i32* %2
ret i32 %87
}

LLVM IR (-O2):
define i32 @min_divisible_by(i32 %0) {
%2 = and i32 %0, 3
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = srem i32 %0, 6
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = icmp slt i32 %0, 19
br i1 %8, label %14, label %16
9: ; preds = %30, %16, %23, %28
%10 = phi i32 [ %29, %28 ], [ %24, %23 ], [ %17, %16 ], [ %32, %30 ]
%11 = phi i32 [ %29, %28 ], [ 9, %23 ], [ 6, %16 ], [ %32, %30 ]
%12 = tail call i32 @min_divisible_by(i32 %10)
%13 = tail call i32 @min(i32 %11, i32 %12)
br label %14
14: ; preds = %40, %36, %9, %34, %1, %7, %21
%15 = phi i32 [ 4, %1 ], [ 6, %7 ], [ 9, %21 ], [ %0, %34 ], [ %13, %9 ], [ %0, %40 ], [ %37, %36 ]
ret i32 %15
16: ; preds = %7
%17 = udiv i32 %0, 6
br label %9
18: ; preds = %4
%19 = srem i32 %0, 9
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = icmp slt i32 %0, 28
br i1 %22, label %14, label %23
23: ; preds = %21
%24 = udiv i32 %0, 9
br label %9
25: ; preds = %18
%26 = and i32 %0, 1
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = sdiv i32 %0, 2
br label %9
30: ; preds = %25
%31 = srem i32 %0, 3
%32 = sdiv i32 %0, 3
%33 = icmp eq i32 %31, 0
br i1 %33, label %9, label %34
34: ; preds = %30
%35 = icmp slt i32 %0, 16
br i1 %35, label %14, label %36
36: ; preds = %34, %40
%37 = phi i32 [ %41, %40 ], [ 4, %34 ]
%38 = srem i32 %0, %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %14, label %40
40: ; preds = %36
%41 = add nuw nsw i32 %37, 1
%42 = icmp ugt i32 %37, 46339
%43 = mul nsw i32 %41, %41
%44 = icmp sgt i32 %43, %0
%45 = select i1 %42, i1 true, i1 %44
br i1 %45, label %14, label %36
}