#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 get_count_ip();
int /*<<< orphan*/ sml_printf(char *, int, int);
main(int argc, char **argv) {
  static int count = 0;
  int loops = 0;
  int idx;
  loops = get_count_ip();
  for (idx = 1; idx <= loops; idx++) {
    count += idx;
  }
  sml_printf("n = %d : sigma n = %d\n", loops, count);
  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)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <get_count_ip@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1177 <main+0x57>
mov    -0x18(%rbp),%eax
add    0x2ed1(%rip),%eax
mov    %eax,0x2ecb(%rip)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <main+0x2e>
mov    -0x14(%rbp),%esi
mov    0x2eb4(%rip),%edx
lea    0xe79(%rip),%rdi
call   1030 <sml_printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <get_count_ip@plt>
mov    0x2f06(%rip),%edx
test   %eax,%eax
jle    1150 <main+0x30>
lea    (%rdx,%rax,2),%ecx
lea    -0x1(%rax),%edx
mov    %eax,%esi
add    $0xfffffffe,%esi
imul   %rdx,%rsi
shr    %rsi
lea    (%rsi,%rcx,1),%edx
add    $0xffffffff,%edx
mov    %edx,0x2ee4(%rip)
lea    0xea9(%rip),%rdi
mov    %eax,%esi
call   1030 <sml_printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@main.count = internal global i32 0
@.str = [23 x i8] c"n = %d : sigma n = %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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call i32 (...) @get_count_ip()
store i32 %8, i32* %6
store i32 1, i32* %7
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i32, i32* %7
%15 = load i32, i32* @main.count
%16 = add nsw i32 %15, %14
store i32 %16, i32* @main.count
br label %17
17: ; preds = %13
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %9
20: ; preds = %9
%21 = load i32, i32* %6
%22 = load i32, i32* @main.count
%23 = call i32 @sml_printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
ret i32 0
}

LLVM IR (-O2):
@main.count = internal unnamed_addr global i32 0
@.str = [23 x i8] c"n = %d : sigma n = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @get_count_ip()
%4 = load i32, i32* @main.count
%5 = icmp slt i32 %3, 1
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = shl nuw i32 %3, 1
%8 = add i32 %4, %7
%9 = add nsw i32 %3, -1
%10 = zext i32 %9 to i33
%11 = add nsw i32 %3, -2
%12 = zext i32 %11 to i33
%13 = mul i33 %10, %12
%14 = lshr i33 %13, 1
%15 = trunc i33 %14 to i32
%16 = add i32 %8, %15
%17 = add i32 %16, -1
store i32 %17, i32* @main.count
br label %18
18: ; preds = %6, %2
%19 = phi i32 [ %17, %6 ], [ %4, %2 ]
%20 = tail call i32 @sml_printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %19)
ret i32 0
}