#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int N, K;
  printf("N=");
  scanf("%i", &N);
  printf("K=");
  scanf("%i", &K);
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += K + i;
  printf("N=%i K=%i sum=%i\n", N, K, sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119f <main+0x7f>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <main+0x59>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec8(%rip),%r14
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
test   %esi,%esi
jle    1183 <main+0x63>
lea    -0x1(%rsi),%eax
lea    0x1(%rdx),%ebx
imul   %eax,%ebx
lea    -0x2(%rsi),%ecx
imul   %rax,%rcx
shr    %rcx
add    %edx,%ebx
add    %ecx,%ebx
lea    0xe7f(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"N=\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [3 x i8] c"K=\00"
@.str.3 = [18 x i8] c"N=%i K=%i sum=%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %5
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32, i32* %3
%16 = load i32, i32* %5
%17 = add nsw i32 %15, %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, %17
store i32 %19, i32* %4
br label %20
20: ; preds = %14
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %10
23: ; preds = %10
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"N=\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [3 x i8] c"K=\00"
@.str.3 = [18 x i8] c"N=%i K=%i sum=%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
%11 = load i32, i32* %2
br i1 %10, label %12, label %24
12: ; preds = %0
%13 = add nsw i32 %9, -1
%14 = add i32 %11, 1
%15 = mul i32 %13, %14
%16 = zext i32 %13 to i33
%17 = add nsw i32 %9, -2
%18 = zext i32 %17 to i33
%19 = mul i33 %16, %18
%20 = lshr i33 %19, 1
%21 = trunc i33 %20 to i32
%22 = add i32 %11, %15
%23 = add i32 %22, %21
br label %24
24: ; preds = %0, %12
%25 = phi i32 [ %23, %12 ], [ 0, %0 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %11, i32 %25)
ret i32 0
}