#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 */
struct timeval {
  long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long numberofSequences(long);
int /*<<< orphan*/ printf(char *, long);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  long i = 0, maxNumber = 0, maxSequence = 0, sequence;
  for (i = 1; i < (1000000); i++) {
    sequence = numberofSequences(i);
    if (sequence > maxSequence) {
      maxSequence = sequence;
      maxNumber = i;
    }
  }
  printf("%ld", maxNumber);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
jge    11bb <main+0x8b>
mov    -0x20(%rbp),%rdi
call   1040 <numberofSequences@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jle    11a5 <main+0x75>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11aa <main+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116c <main+0x3c>
mov    -0x28(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x1,%ebx
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <numberofSequences@plt>
cmp    %r15,%rax
cmovg  %rbx,%r14
cmovg  %rax,%r15
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1150 <main+0x20>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
sub    (%rsp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"%ld\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
store i64 1, i64* %4
br label %9
9: ; preds = %22, %0
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 1000000
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i64, i64* %4
%14 = call i64 @numberofSequences(i64 %13)
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = icmp sgt i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i64, i64* %7
store i64 %19, i64* %6
%20 = load i64, i64* %4
store i64 %20, i64* %5
br label %21
21: ; preds = %18, %12
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = add nsw i64 %23, 1
store i64 %24, i64* %4
br label %9
25: ; preds = %9
%26 = load i64, i64* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%32 = load i64, i64* %31
%33 = sub nsw i64 %30, %32
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %33)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"%ld\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 1, %0 ], [ %14, %6 ]
%8 = phi i64 [ 0, %0 ], [ %13, %6 ]
%9 = phi i64 [ 0, %0 ], [ %12, %6 ]
%10 = tail call i64 @numberofSequences(i64 %7)
%11 = icmp sgt i64 %10, %8
%12 = select i1 %11, i64 %7, i64 %9
%13 = select i1 %11, i64 %10, i64 %8
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, 1000000
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %12)
%18 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%22 = load i64, i64* %21
%23 = sub nsw i64 %20, %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %23)
ret i32 0
}