#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int unit_fraction_cycle_len(int);
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 < 1)
    return 1;
  int longest_cycle = 0;
  int fraction = 0;
  for (int i = 1; i < N; i++) {
    int len = unit_fraction_cycle_len(i);
    if (len > longest_cycle) {
      longest_cycle = len;
      fraction = i;
    }
  }
  printf("%d\n", fraction);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    121b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11ae <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xdb>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1205 <main+0xc5>
mov    -0x20(%rbp),%edi
call   1030 <unit_fraction_cycle_len@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11f2 <main+0xb2>
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <main+0xb7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c3 <main+0x83>
mov    -0x1c(%rbp),%esi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    11a9 <main+0x69>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11c1 <main+0x81>
mov    %eax,%r15d
xor    %r14d,%r14d
mov    $0x0,%r12d
cmp    $0x1,%eax
je     1198 <main+0x58>
xor    %r12d,%r12d
mov    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1030 <unit_fraction_cycle_len@plt>
cmp    %ebx,%eax
cmovg  %eax,%ebx
cmovg  %ebp,%r12d
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1180 <main+0x40>
lea    0xe70(%rip),%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
jmp    11c7 <main+0x87>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %48
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %3
br label %48
27: ; preds = %19
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
br label %28
28: ; preds = %42, %27
%29 = load i32, i32* %9
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i32, i32* %9
%34 = call i32 @unit_fraction_cycle_len(i32 %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = load i32, i32* %7
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i32, i32* %10
store i32 %39, i32* %7
%40 = load i32, i32* %9
store i32 %40, i32* %8
br label %41
41: ; preds = %38, %32
br label %42
42: ; preds = %41
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %28
45: ; preds = %28
%46 = load i32, i32* %8
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %26, %13
%49 = load i32, i32* %3
ret i32 %49
}

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 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %28, label %13
13: ; preds = %8
%14 = icmp eq i32 %11, 1
br i1 %14, label %15, label %18
15: ; preds = %18, %13
%16 = phi i32 [ 0, %13 ], [ %25, %18 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %28
18: ; preds = %13, %18
%19 = phi i32 [ %26, %18 ], [ 1, %13 ]
%20 = phi i32 [ %25, %18 ], [ 0, %13 ]
%21 = phi i32 [ %24, %18 ], [ 0, %13 ]
%22 = tail call i32 @unit_fraction_cycle_len(i32 %19)
%23 = icmp sgt i32 %22, %21
%24 = select i1 %23, i32 %22, i32 %21
%25 = select i1 %23, i32 %19, i32 %20
%26 = add nuw nsw i32 %19, 1
%27 = icmp eq i32 %26, %11
br i1 %27, label %15, label %18
28: ; preds = %15, %8, %4
%29 = phi i32 [ 1, %4 ], [ 0, %15 ], [ 1, %8 ]
ret i32 %29
}