#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 */
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n, num = 1, sum = 0;
  printf("Enter the number of terms you want to sum up: ");
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    sum += num;
    num += pow(2, i);
  }
  printf("\nThe sum of a series is %d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11af <main+0x7f>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <main+0x42>
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    118c <main+0x5c>
mov    $0x1,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    %ebx,%r14d
mov    $0x2,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
add    %ebx,%eax
mov    %eax,%ebx
cmp    0xc(%rsp),%ebp
jl     1170 <main+0x40>
lea    0xe9c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Enter the number of terms you want to sum up: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0AThe sum of a series is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 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)
store i32 1, i32* %5
br label %8
8: ; preds = %22, %0
%9 = load i32, i32* %5
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, %13
store i32 %15, i32* %4
%16 = load i32, i32* %5
%17 = call i64 @pow(i32 2, i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
br label %22
22: ; preds = %12
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %8
25: ; preds = %8
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [47 x i8] c"Enter the number of terms you want to sum up: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0AThe sum of a series is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %10, %0
%8 = phi i32 [ 0, %0 ], [ %14, %10 ]
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %8)
ret i32 0
10: ; preds = %0, %10
%11 = phi i32 [ %18, %10 ], [ 1, %0 ]
%12 = phi i32 [ %14, %10 ], [ 0, %0 ]
%13 = phi i32 [ %17, %10 ], [ 1, %0 ]
%14 = add nsw i32 %12, %13
%15 = call i64 @pow(i32 2, i32 %11)
%16 = trunc i64 %15 to i32
%17 = add i32 %13, %16
%18 = add nuw nsw i32 %11, 1
%19 = load i32, i32* %1
%20 = icmp slt i32 %11, %19
br i1 %20, label %10, label %7
}