#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_s(char *, int *);
int /*<<< orphan*/ system(char *);
void main() {
  int power, number, i, flag;
  double product;
  product = 1.0;
  flag = 0;
  i = 0;
  printf("Enter a number: ");
  scanf_s("%d", &number);
  printf("Enter a power: ");
  scanf_s("%d", &power);
  if (power < 0) {
    power = power * -1;
    flag = 1;
  }
  while (i < power) {
    product = product * number;
    i++;
  }
  if (flag == 1)
    product = 1 / product;
  printf("%d power of %d is: %f\n", power, number, product);
  system("pause");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf_s@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf_s@plt>
cmpl   $0x0,-0x4(%rbp)
jge    11a7 <main+0x77>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    11ac <main+0x7c>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d9 <main+0xa9>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <main+0x7c>
cmpl   $0x1,-0x10(%rbp)
jne    11f5 <main+0xc5>
movsd  0xe15(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe2e(%rip),%rdi
call   1030 <system@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecf(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf_s@plt>
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf_s@plt>
mov    0xc(%rsp),%eax
mov    %eax,%esi
test   %eax,%eax
js     118e <main+0x5e>
jne    1194 <main+0x64>
movsd  0xe7a(%rip),%xmm0
xor    %esi,%esi
mov    0x8(%rsp),%edx
jmp    11f9 <main+0xc9>
neg    %esi
mov    %esi,0xc(%rsp)
mov    0x8(%rsp),%edx
cvtsi2sd %edx,%xmm1
lea    -0x1(%rsi),%edi
mov    %esi,%ecx
and    $0x7,%ecx
cmp    $0x7,%edi
jae    11b3 <main+0x83>
movsd  0xe4f(%rip),%xmm0
jmp    11e5 <main+0xb5>
mov    %esi,%edi
and    $0xfffffff8,%edi
movsd  0xe40(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
add    $0xfffffff8,%edi
jne    11c0 <main+0x90>
test   %ecx,%ecx
je     11f9 <main+0xc9>
nopl   0x0(%rax)
mulsd  %xmm1,%xmm0
add    $0xffffffff,%ecx
jne    11f0 <main+0xc0>
test   %eax,%eax
jns    120d <main+0xdd>
movsd  0xdfb(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe21(%rip),%rdi
call   1030 <system@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Enter a power: \00"
@.str.3 = [23 x i8] c"%d power of %d is: %f\0A\00"
@.str.4 = [6 x i8] c"pause\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store double 1.000000e+00, double* %5
store i32 0, i32* %4
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf_s(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 ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* %1
%14 = mul nsw i32 %13, -1
store i32 %14, i32* %1
store i32 1, i32* %4
br label %15
15: ; preds = %12, %0
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %3
%18 = load i32, i32* %1
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load double, double* %5
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = fmul double %21, %23
store double %24, double* %5
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %16
27: ; preds = %16
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load double, double* %5
%32 = fdiv double 1.000000e+00, %31
store double %32, double* %5
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %1
%35 = load i32, i32* %2
%36 = load double, double* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35, double %36)
%38 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Enter a power: \00"
@.str.3 = [23 x i8] c"%d power of %d is: %f\0A\00"
@.str.4 = [6 x i8] c"pause\00"
define void @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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = sub nsw i32 0, %9
store i32 %12, i32* %1
br label %17
13: ; preds = %0
%14 = icmp eq i32 %9, 0
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = load i32, i32* %2
br label %49
17: ; preds = %11, %13
%18 = phi i32 [ %12, %11 ], [ %9, %13 ]
%19 = load i32, i32* %2
%20 = sitofp i32 %19 to double
%21 = add i32 %18, -1
%22 = and i32 %18, 7
%23 = icmp ult i32 %21, 7
br i1 %23, label %39, label %24
24: ; preds = %17
%25 = and i32 %18, -8
br label %26
26: ; preds = %26, %24
%27 = phi double [ 1.000000e+00, %24 ], [ %36, %26 ]
%28 = phi i32 [ 0, %24 ], [ %37, %26 ]
%29 = fmul double %27, %20
%30 = fmul double %29, %20
%31 = fmul double %30, %20
%32 = fmul double %31, %20
%33 = fmul double %32, %20
%34 = fmul double %33, %20
%35 = fmul double %34, %20
%36 = fmul double %35, %20
%37 = add i32 %28, 8
%38 = icmp eq i32 %37, %25
br i1 %38, label %39, label %26
39: ; preds = %26, %17
%40 = phi double [ undef, %17 ], [ %36, %26 ]
%41 = phi double [ 1.000000e+00, %17 ], [ %36, %26 ]
%42 = icmp eq i32 %22, 0
br i1 %42, label %49, label %43
43: ; preds = %39, %43
%44 = phi double [ %46, %43 ], [ %41, %39 ]
%45 = phi i32 [ %47, %43 ], [ 0, %39 ]
%46 = fmul double %44, %20
%47 = add i32 %45, 1
%48 = icmp eq i32 %47, %22
br i1 %48, label %49, label %43
49: ; preds = %39, %43, %15
%50 = phi i32 [ 0, %15 ], [ %18, %43 ], [ %18, %39 ]
%51 = phi i32 [ %16, %15 ], [ %19, %43 ], [ %19, %39 ]
%52 = phi double [ 1.000000e+00, %15 ], [ %40, %39 ], [ %46, %43 ]
%53 = fdiv double 1.000000e+00, %52
%54 = select i1 %10, double %53, double %52
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51, double %54)
%56 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret void
}