#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 pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  int a, sum = 0, n, i, j, x, b = 1;
  printf("Enter the value of n and x\n");
  scanf("%d %d", &n, &x);
  for (i = 0, j = 0; i <= n; i++, j++) {
    if ((i % 2) == 0) {
      a = pow((-1), j) * pow(x, i);
      b = i * b;
      sum = sum + (a / b);
    }
    printf("The sum of the computed cosine series is \n");
    printf("x-x^3/3!+...\n");
    printf("%d", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x20(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1228 <main+0xf8>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e4 <main+0xb4>
mov    -0x18(%rbp),%esi
mov    $0xffffffff,%edi
call   1050 <pow@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117d <main+0x4d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
js     11fc <main+0xbc>
mov    $0x1,%r13d
lea    0xe99(%rip),%r15
lea    0xebc(%rip),%r12
lea    0xe6d(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11c7 <main+0x87>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
jge    11fc <main+0xbc>
test   $0x1,%bl
jne    11a0 <main+0x60>
mov    $0xffffffff,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
mov    %ebp,0x10(%rsp)
mov    %eax,%ebp
mov    0x14(%rsp),%edi
mov    %ebx,%esi
call   1060 <pow@plt>
imul   %ebp,%eax
mov    0x10(%rsp),%ebp
imul   %ebx,%r13d
cltd
idiv   %r13d
add    %eax,%ebp
jmp    11a0 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the value of n and x\0A\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [43 x i8] c"The sum of the computed cosine series is \0A\00"
@.str.3 = [14 x i8] c"x-x^3/3!+...\0A\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 1, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %7)
store i32 0, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %39, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i32, i32* %5
%17 = srem i32 %16, 2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i32, i32* %6
%21 = call i32 @pow(i32 -1, i32 %20)
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = call i32 @pow(i32 %22, i32 %23)
%25 = mul nsw i32 %21, %24
store i32 %25, i32* %2
%26 = load i32, i32* %5
%27 = load i32, i32* %8
%28 = mul nsw i32 %26, %27
store i32 %28, i32* %8
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = load i32, i32* %8
%32 = sdiv i32 %30, %31
%33 = add nsw i32 %29, %32
store i32 %33, i32* %3
br label %34
34: ; preds = %19, %15
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %34
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %11
44: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%d %d\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [27 x i8] c"Enter the value of n and x\00"
@str.5 = [42 x i8] c"The sum of the computed cosine series is \00"
@str.6 = [13 x i8] c"x-x^3/3!+...\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %0, %23
%10 = phi i32 [ %25, %23 ], [ 1, %0 ]
%11 = phi i32 [ %29, %23 ], [ 0, %0 ]
%12 = phi i32 [ %24, %23 ], [ 0, %0 ]
%13 = and i32 %11, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = call i32 @pow(i32 -1, i32 %11)
%17 = load i32, i32* %2
%18 = call i32 @pow(i32 %17, i32 %11)
%19 = mul nsw i32 %18, %16
%20 = mul nsw i32 %10, %11
%21 = sdiv i32 %19, %20
%22 = add nsw i32 %21, %12
br label %23
23: ; preds = %15, %9
%24 = phi i32 [ %22, %15 ], [ %12, %9 ]
%25 = phi i32 [ %20, %15 ], [ %10, %9 ]
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%29 = add nuw nsw i32 %11, 1
%30 = load i32, i32* %1
%31 = icmp slt i32 %11, %30
br i1 %31, label %9, label %32
32: ; preds = %23, %0
ret i32 0
}