#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);
void series1(int n) {
  int sum, i;
  sum = 0;
  for (i = 0; i < n; i++) {
    if (i == n - 1)
      printf("(1+%d)", i);
    else
      printf("(1+%d)+", i);
    sum += 1 + i;
  }
  printf("\nSum of above series is %d\n", sum);
}


x86 assembly (clang, -O0):
<series1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1183 <series1+0x73>
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    115a <series1+0x4a>
mov    -0xc(%rbp),%esi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
jmp    1169 <series1+0x59>
mov    -0xc(%rbp),%esi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <series1+0x19>
mov    -0x8(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<series1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    116f <series1+0x5f>
mov    %edi,%r13d
lea    -0x1(%r13),%r14d
neg    %r13d
xor    %ebp,%ebp
mov    $0x1,%ebx
lea    0xec9(%rip),%r15
lea    0xec9(%rip),%r12
jmp    1160 <series1+0x50>
lea    -0x1(%rbx),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    %ebx,%ebp
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     1171 <series1+0x61>
mov    %r13d,%eax
add    %ebx,%eax
jne    1140 <series1+0x30>
mov    %r15,%rdi
mov    %r14d,%esi
jmp    1146 <series1+0x36>
xor    %ebp,%ebp
lea    0xe97(%rip),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"(1+%d)\00"
@.str.1 = [8 x i8] c"(1+%d)+\00"
@.str.2 = [28 x i8] c"\0ASum of above series is %d\0A\00"
define void @series1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %25, %1
%6 = load i32, i32* %4
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %28
9: ; preds = %5
%10 = load i32, i32* %4
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 1
%13 = icmp eq i32 %10, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %20
17: ; preds = %9
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = add nsw i32 1, %21
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %22
store i32 %24, i32* %3
br label %25
25: ; preds = %20
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %5
28: ; preds = %5
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"(1+%d)\00"
@.str.1 = [8 x i8] c"(1+%d)+\00"
@.str.2 = [28 x i8] c"\0ASum of above series is %d\0A\00"
define void @series1(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %17
3: ; preds = %1
%4 = add nsw i32 %0, -1
br label %5
5: ; preds = %3, %13
%6 = phi i32 [ 0, %3 ], [ %14, %13 ]
%7 = phi i32 [ 0, %3 ], [ %15, %13 ]
%8 = icmp eq i32 %6, %4
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %13
11: ; preds = %5
%12 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %13
13: ; preds = %11, %9
%14 = add nuw nsw i32 %6, 1
%15 = add nuw nsw i32 %14, %7
%16 = icmp eq i32 %14, %0
br i1 %16, label %17, label %5
17: ; preds = %13, %1
%18 = phi i32 [ 0, %1 ], [ %15, %13 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret void
}