#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 /*<<< orphan*/ printf(char *, ...);
long sqrt(long);
int sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int limit;
  long triangle = 0;
  int count = 0;
  bool found = false;
  if (sscanf(argv[1], "%i", &limit) != 1) {
    printf("error");
  }
  for (long n = 1; n > 0; n++) {
    count = 0;
    triangle += n;
    for (long i = 1; i < sqrt(triangle); i++) {
      if (triangle % 2 != 0) {
        break;
      }
      if (triangle % i == 0) {
        count += 2;
        if (count > limit) {
          found = true;
          printf("result: %lu", triangle);
          break;
        }
      }
    }
    if (found == true) {
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe95(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     118b <main+0x5b>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    127e <main+0x14e>
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jge    1259 <main+0x129>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     11f7 <main+0xc7>
jmp    1259 <main+0x129>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x38(%rbp)
cmp    $0x0,%rdx
jne    1243 <main+0x113>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    123e <main+0x10e>
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1259 <main+0x129>
jmp    1243 <main+0x113>
jmp    1248 <main+0x118>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11b9 <main+0x89>
cmpl   $0x1,-0x28(%rbp)
jne    1268 <main+0x138>
jmp    127e <main+0x14e>
jmp    126d <main+0x13d>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1193 <main+0x63>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xebe(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     115f <main+0x2f>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r14d
xor    %r15d,%r15d
jmp    1174 <main+0x44>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
add    %r14,%r15
mov    %r15,%rdi
call   1050 <sqrt@plt>
mov    %r15d,%ecx
and    $0x1,%ecx
cmp    $0x2,%rax
jl     1170 <main+0x40>
test   %rcx,%rcx
jne    1170 <main+0x40>
xor    %ebp,%ebp
mov    $0x1,%ebx
jmp    11b1 <main+0x81>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <sqrt@plt>
cmp    %rax,%rbx
jge    1170 <main+0x40>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11d0 <main+0xa0>
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    11a0 <main+0x70>
jmp    11dc <main+0xac>
nopl   0x0(%rax)
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    11a0 <main+0x70>
add    $0x2,%ebp
cmp    0x4(%rsp),%ebp
jle    11a0 <main+0x70>
lea    0xe1d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [12 x i8] c"result: %lu\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
store i64 1, i64* %10
br label %20
20: ; preds = %61, %19
%21 = load i64, i64* %10
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %64
23: ; preds = %20
store i32 0, i32* %8
%24 = load i64, i64* %10
%25 = load i64, i64* %7
%26 = add nsw i64 %25, %24
store i64 %26, i64* %7
store i64 1, i64* %11
br label %27
27: ; preds = %53, %23
%28 = load i64, i64* %11
%29 = load i64, i64* %7
%30 = call i64 @sqrt(i64 %29)
%31 = icmp slt i64 %28, %30
br i1 %31, label %32, label %56
32: ; preds = %27
%33 = load i64, i64* %7
%34 = srem i64 %33, 2
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %56
37: ; preds = %32
%38 = load i64, i64* %7
%39 = load i64, i64* %11
%40 = srem i64 %38, %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 2
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = load i32, i32* %6
%47 = icmp sgt i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %42
store i32 1, i32* %9
%49 = load i64, i64* %7
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %49)
br label %56
51: ; preds = %42
br label %52
52: ; preds = %51, %37
br label %53
53: ; preds = %52
%54 = load i64, i64* %11
%55 = add nsw i64 %54, 1
store i64 %55, i64* %11
br label %27
56: ; preds = %48, %36, %27
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %56
br label %64
60: ; preds = %56
br label %61
61: ; preds = %60
%62 = load i64, i64* %10
%63 = add nsw i64 %62, 1
store i64 %63, i64* %10
br label %20
64: ; preds = %59, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [12 x i8] c"result: %lu\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
br label %12
12: ; preds = %11, %37
%13 = phi i64 [ %15, %37 ], [ 0, %11 ]
%14 = phi i64 [ %38, %37 ], [ 1, %11 ]
%15 = add nuw nsw i64 %14, %13
%16 = call i64 @sqrt(i64 %15)
%17 = icmp sgt i64 %16, 1
%18 = and i64 %15, 1
%19 = icmp eq i64 %18, 0
%20 = and i1 %17, %19
br i1 %20, label %21, label %37
21: ; preds = %12, %32
%22 = phi i64 [ %34, %32 ], [ 1, %12 ]
%23 = phi i32 [ %33, %32 ], [ 0, %12 ]
%24 = urem i64 %15, %22
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = add nsw i32 %23, 2
%28 = load i32, i32* %3
%29 = icmp sgt i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %15)
ret i32 0
32: ; preds = %21, %26
%33 = phi i32 [ %27, %26 ], [ %23, %21 ]
%34 = add nuw nsw i64 %22, 1
%35 = call i64 @sqrt(i64 %15)
%36 = icmp slt i64 %34, %35
br i1 %36, label %21, label %37
37: ; preds = %32, %12
%38 = add nuw nsw i64 %14, 1
br label %12
}