#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 atoi(char *);
int find_minimum(int, int, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <N>\n", argv[0]);
    return 1;
  }
  int N = atoi(argv[1]);
  if (N < 2)
    return 1;
  int sum = 0;
  int search_limit = 1300;
  int boundary = 0;
  while ((sum = find_minimum(N, search_limit, &boundary)) == 0)
    search_limit *= 10;
  if (boundary > search_limit) {
    search_limit = boundary;
    sum = find_minimum(N, search_limit, &boundary);
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1224 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11ae <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1224 <main+0xe4>
movl   $0x0,-0x18(%rbp)
movl   $0x514,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <find_minimum@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11ea <main+0xaa>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c3 <main+0x83>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    120e <main+0xce>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <find_minimum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11db <main+0x9b>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    $0x1,%eax
cmp    $0x2,%ebp
jl     11f8 <main+0xb8>
movl   $0x0,0xc(%rsp)
mov    $0x514,%ebx
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
mov    $0x514,%esi
call   1030 <find_minimum@plt>
test   %eax,%eax
jne    11b5 <main+0x75>
mov    $0x514,%ebx
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <find_minimum@plt>
test   %eax,%eax
je     11a0 <main+0x60>
mov    0xc(%rsp),%esi
cmp    %ebx,%esi
jle    11c9 <main+0x89>
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1030 <find_minimum@plt>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11f8 <main+0xb8>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %47
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %3
br label %47
26: ; preds = %18
store i32 0, i32* %7
store i32 1300, i32* %8
store i32 0, i32* %9
br label %27
27: ; preds = %32, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = call i32 @find_minimum(i32 %28, i32 %29, i32* %9)
store i32 %30, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %8
%34 = mul nsw i32 %33, 10
store i32 %34, i32* %8
br label %27
35: ; preds = %27
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* %9
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = load i32, i32* %8
%43 = call i32 @find_minimum(i32 %41, i32 %42, i32* %9)
store i32 %43, i32* %7
br label %44
44: ; preds = %39, %35
%45 = load i32, i32* %7
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %45)
store i32 0, i32* %3
br label %47
47: ; preds = %44, %25, %12
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %33
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 2
br i1 %13, label %33, label %14
14: ; preds = %9
%15 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%16 = call i32 @find_minimum(i32 %12, i32 1300, i32* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14, %18
%19 = phi i32 [ %20, %18 ], [ 1300, %14 ]
%20 = mul nuw nsw i32 %19, 10
%21 = call i32 @find_minimum(i32 %12, i32 %20, i32* %3)
%22 = icmp eq i32 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %18, %14
%24 = phi i32 [ 1300, %14 ], [ %20, %18 ]
%25 = phi i32 [ %16, %14 ], [ %21, %18 ]
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, %24
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @find_minimum(i32 %12, i32 %26, i32* %3)
br label %30
30: ; preds = %28, %23
%31 = phi i32 [ %29, %28 ], [ %25, %23 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %9, %5
%34 = phi i32 [ 1, %5 ], [ 0, %30 ], [ 1, %9 ]
ret i32 %34
}