#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int sum_of_powers(int);
int main() {
  printf("Enter \"help\" for a list of commands\n");
  while (1) {
    char input[10];
    int valid_character = 0;
    int i;
    while (valid_character == 0) {
      printf("Please enter a command: ");
      fgets(input, 20, stdin);
      for (i = 0; i < strlen(input) - 1; i++) {
        if (input[i] == ' ')
          valid_character = 1;
        else if (input[i] >= 'a' && input[i] <= 'z') {
          input[i] = input[i] - 'a' + 'A';
          valid_character = 1;
        } else if (input[i] >= 'A' && input[i] <= 'Z' ||
                   input[i] >= '0' && input[i] <= '9')
          valid_character = 1;
        else {
          valid_character = 0;
          printf("\nYou entered an invalid entry!\n");
          printf("You entered an invalid character.\n\n");
          printf("Enter \"help\" for a list of commands\n");
          break;
        }
      }
    }
    if (input[0] == 'Q' && input[1] == 'U' && input[2] == 'I' &&
        input[3] == 'T') {
      printf("\n***************************************************************"
             "****************\n");
      printf("Thanks for using this sum of powers application!\n");
      printf("*****************************************************************"
             "**************\n");
      return 0;
    } else if (input[0] == 'H' && input[1] == 'E' && input[2] == 'L' &&
               input[3] == 'P') {
      printf("\n***************************************************************"
             "****************\n");
      printf("[quit]\n");
      printf("Terminates execution.\n\n");
      printf("[help]\n");
      printf("Prints a short help doc to the terminal.\n\n");
      printf("[<n>]\n");
      printf("<n> is a positive number.  The command will print out the sum of "
             "base n to\n");
      printf("power n with the starting value of n by 1 at each summand until "
             "the value n\n");
      printf("equals 1.\n");
      printf("*****************************************************************"
             "**************\n\n");
    } else if (input[0] >= '0' && input[0] <= '9') {
      int n;
      int valid_format = 0;
      n = 0;
      for (i = 0; i < strlen(input) - 1; i++) {
        if (input[i] >= '0' && input[i] <= '9')
          valid_format = 1;
        else {
          valid_format = 0;
          printf("\nYou entered an invalid entry!\n");
          printf("Positive numbers are only allowed.\n");
          break;
        }
      }
      n = atoi(input);
      if (valid_format == 1) {
        int count = n;
        printf("\n");
        while (count > 1) {
          printf("%d^%d + ", count, count);
          count--;
        }
        printf("%d^%d = ", count, count);
        printf("%d\n", sum_of_powers(n));
        printf("\n");
      }
    } else {
      printf("You entered an invalid command!\n\n");
      printf("Enter \"help\" for a list of commands\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12dc <main+0x18c>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1050 <fgets@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12d7 <main+0x187>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    11e7 <main+0x97>
movl   $0x1,-0x14(%rbp)
jmp    12c4 <main+0x174>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x61,%eax
jl     1230 <main+0xe0>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x7a,%eax
jg     1230 <main+0xe0>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
sub    $0x61,%eax
add    $0x41,%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0xe(%rbp,%rax,1)
movl   $0x1,-0x14(%rbp)
jmp    12bf <main+0x16f>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x41,%eax
jl     1254 <main+0x104>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x5a,%eax
jle    1278 <main+0x128>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     1284 <main+0x134>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jg     1284 <main+0x134>
movl   $0x1,-0x14(%rbp)
jmp    12ba <main+0x16a>
movl   $0x0,-0x14(%rbp)
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d7 <main+0x187>
jmp    12bf <main+0x16f>
jmp    12c4 <main+0x174>
jmp    12c9 <main+0x179>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11aa <main+0x5a>
jmp    1174 <main+0x24>
movsbl -0xe(%rbp),%eax
cmp    $0x51,%eax
jne    1342 <main+0x1f2>
movsbl -0xd(%rbp),%eax
cmp    $0x55,%eax
jne    1342 <main+0x1f2>
movsbl -0xc(%rbp),%eax
cmp    $0x49,%eax
jne    1342 <main+0x1f2>
movsbl -0xb(%rbp),%eax
cmp    $0x54,%eax
jne    1342 <main+0x1f2>
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
movsbl -0xe(%rbp),%eax
cmp    $0x48,%eax
jne    1407 <main+0x2b7>
movsbl -0xd(%rbp),%eax
cmp    $0x45,%eax
jne    1407 <main+0x2b7>
movsbl -0xc(%rbp),%eax
cmp    $0x4c,%eax
jne    1407 <main+0x2b7>
movsbl -0xb(%rbp),%eax
cmp    $0x50,%eax
jne    1407 <main+0x2b7>
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1576 <main+0x426>
movsbl -0xe(%rbp),%eax
cmp    $0x30,%eax
jl     1555 <main+0x405>
movsbl -0xe(%rbp),%eax
cmp    $0x39,%eax
jg     1555 <main+0x405>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14c0 <main+0x370>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     1485 <main+0x335>
movslq -0x18(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jg     1485 <main+0x335>
movl   $0x1,-0x20(%rbp)
jmp    14ad <main+0x35d>
movl   $0x0,-0x20(%rbp)
lea    0xbab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14c0 <main+0x370>
jmp    14b2 <main+0x362>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1436 <main+0x2e6>
lea    -0xe(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1550 <main+0x400>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x24(%rbp)
jle    1516 <main+0x3c6>
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    14ea <main+0x39a>
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <sum_of_powers@plt>
mov    %eax,%esi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1571 <main+0x421>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xa96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1576 <main+0x426>
jmp    157b <main+0x42b>
jmp    116d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x10f9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6f(%rip),%r15
mov    0x2e50(%rip),%r12
lea    0xa(%rsp),%rbx
lea    0xe75(%rip),%r13
jmp    1220 <main+0xb0>
lea    0x100d(%rip),%rdi
call   1040 <puts@plt>
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
lea    0xf12(%rip),%rdi
call   1040 <puts@plt>
lea    0xf52(%rip),%rdi
call   1040 <puts@plt>
lea    0xf50(%rip),%rdi
call   1040 <puts@plt>
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     1220 <main+0xb0>
xor    %ebp,%ebp
jmp    126c <main+0xfc>
nopl   0x0(%rax)
add    $0xe0,%al
mov    %al,0xa(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jge    12c0 <main+0x150>
movzbl 0xa(%rsp,%rbp,1),%eax
cmp    $0x20,%al
je     1256 <main+0xe6>
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
jbe    1250 <main+0xe0>
lea    -0x41(%rax),%ecx
cmp    $0x1a,%cl
jb     1256 <main+0xe6>
add    $0xd0,%al
cmp    $0xa,%al
jb     1256 <main+0xe6>
lea    0xfaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xfbd(%rip),%rdi
call   1040 <puts@plt>
lea    0xfd4(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xa(%rsp),%al
mov    0xb(%rsp),%cl
mov    0xc(%rsp),%dl
mov    0xd(%rsp),%sil
cmp    $0x51,%al
jne    12e9 <main+0x179>
cmp    $0x55,%cl
jne    12e9 <main+0x179>
cmp    $0x49,%dl
jne    12e9 <main+0x179>
cmp    $0x54,%sil
je     1421 <main+0x2b1>
cmp    $0x48,%al
jne    1301 <main+0x191>
cmp    $0x45,%cl
jne    1301 <main+0x191>
cmp    $0x4c,%dl
jne    1301 <main+0x191>
cmp    $0x50,%sil
je     11a6 <main+0x36>
add    $0xd0,%al
cmp    $0x9,%al
ja     13e7 <main+0x277>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     1220 <main+0xb0>
mov    %eax,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xa(%rsp,%rbp,1),%eax
add    $0xd0,%al
cmp    $0xa,%al
jae    1404 <main+0x294>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jl     1330 <main+0x1c0>
mov    %rbx,%rdi
call   1090 <atoi@plt>
cmp    $0x2,%r14d
jl     1220 <main+0xb0>
mov    %eax,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edx
cmp    $0x2,%ebp
jl     13b1 <main+0x241>
mov    %ebp,0x14(%rsp)
mov    %r13,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    -0x1(%rbp),%eax
cmp    $0x2,%ebp
mov    %eax,%ebp
ja     1390 <main+0x220>
mov    $0x1,%edx
mov    0x14(%rsp),%ebp
lea    0xc6a(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <sum_of_powers@plt>
lea    0xc5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xb0>
lea    0xc41(%rip),%rdi
call   1040 <puts@plt>
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xb0>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
lea    0xc39(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xb0>
lea    0xd92(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
lea    0xd7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter \22help\22 for a list of commands\0A\00"
@.str.1 = [25 x i8] c"Please enter a command: \00"
@stdin = global i32 0
@.str.2 = [32 x i8] c"\0AYou entered an invalid entry!\0A\00"
@.str.3 = [36 x i8] c"You entered an invalid character.\0A\0A\00"
@.str.4 = [82 x i8] c"\0A*******************************************************************************\0A\00"
@.str.5 = [50 x i8] c"Thanks for using this sum of powers application!\0A\00"
@.str.6 = [81 x i8] c"*******************************************************************************\0A\00"
@.str.7 = [8 x i8] c"[quit]\0A\00"
@.str.8 = [24 x i8] c"Terminates execution.\0A\0A\00"
@.str.9 = [8 x i8] c"[help]\0A\00"
@.str.10 = [43 x i8] c"Prints a short help doc to the terminal.\0A\0A\00"
@.str.11 = [7 x i8] c"[<n>]\0A\00"
@.str.12 = [76 x i8] c"<n> is a positive number. The command will print out the sum of base n to\0A\00"
@.str.13 = [77 x i8] c"power n with the starting value of n by 1 at each summand until the value n\0A\00"
@.str.14 = [11 x i8] c"equals 1.\0A\00"
@.str.15 = [82 x i8] c"*******************************************************************************\0A\0A\00"
@.str.16 = [36 x i8] c"Positive numbers are only allowed.\0A\00"
@.str.17 = [2 x i8] c"\0A\00"
@.str.18 = [9 x i8] c"%d^%d + \00"
@.str.19 = [9 x i8] c"%d^%d = \00"
@.str.20 = [4 x i8] c"%d\0A\00"
@.str.21 = [34 x i8] c"You entered an invalid command!\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %0, %223
store i32 0, i32* %3
br label %10
10: ; preds = %97, %9
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %98
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 20, i32 %16)
store i32 0, i32* %4
br label %18
18: ; preds = %94, %13
%19 = load i32, i32* %4
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %19, %22
br i1 %23, label %24, label %97
24: ; preds = %18
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
br label %93
32: ; preds = %24
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp sge i32 %37, 97
br i1 %38, label %39, label %58
39: ; preds = %32
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sle i32 %44, 122
br i1 %45, label %46, label %58
46: ; preds = %39
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = sub nsw i32 %51, 97
%53 = add nsw i32 %52, 65
%54 = trunc i32 %53 to i8
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %56
store i8 %54, i8* %57
store i32 1, i32* %3
br label %92
58: ; preds = %39, %32
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp sge i32 %63, 65
br i1 %64, label %65, label %72
65: ; preds = %58
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp sle i32 %70, 90
br i1 %71, label %86, label %72
72: ; preds = %65, %58
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp sge i32 %77, 48
br i1 %78, label %79, label %87
79: ; preds = %72
%80 = load i32, i32* %4
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp sle i32 %84, 57
br i1 %85, label %86, label %87
86: ; preds = %79, %65
store i32 1, i32* %3
br label %91
87: ; preds = %79, %72
store i32 0, i32* %3
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %97
91: ; preds = %86
br label %92
92: ; preds = %91, %46
br label %93
93: ; preds = %92, %31
br label %94
94: ; preds = %93
%95 = load i32, i32* %4
%96 = add nsw i32 %95, 1
store i32 %96, i32* %4
br label %18
97: ; preds = %87, %18
br label %10
98: ; preds = %10
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp eq i32 %101, 81
br i1 %102, label %103, label %122
103: ; preds = %98
%104 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 85
br i1 %107, label %108, label %122
108: ; preds = %103
%109 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 73
br i1 %112, label %113, label %122
113: ; preds = %108
%114 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = icmp eq i32 %116, 84
br i1 %117, label %118, label %122
118: ; preds = %113
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0))
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
122: ; preds = %113, %108, %103, %98
%123 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%124 = load i8, i8* %123
%125 = sext i8 %124 to i32
%126 = icmp eq i32 %125, 72
br i1 %126, label %127, label %153
127: ; preds = %122
%128 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 69
br i1 %131, label %132, label %153
132: ; preds = %127
%133 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
%134 = load i8, i8* %133
%135 = sext i8 %134 to i32
%136 = icmp eq i32 %135, 76
br i1 %136, label %137, label %153
137: ; preds = %132
%138 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp eq i32 %140, 80
br i1 %141, label %142, label %153
142: ; preds = %137
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0))
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0))
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.12, i64 0, i64 0))
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.13, i64 0, i64 0))
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0))
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.15, i64 0, i64 0))
br label %222
153: ; preds = %137, %132, %127, %122
%154 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%155 = load i8, i8* %154
%156 = sext i8 %155 to i32
%157 = icmp sge i32 %156, 48
br i1 %157, label %158, label %218
158: ; preds = %153
%159 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%160 = load i8, i8* %159
%161 = sext i8 %160 to i32
%162 = icmp sle i32 %161, 57
br i1 %162, label %163, label %218
163: ; preds = %158
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %4
br label %164
164: ; preds = %189, %163
%165 = load i32, i32* %4
%166 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%167 = call i32 @strlen(i8* %166)
%168 = sub nsw i32 %167, 1
%169 = icmp slt i32 %165, %168
br i1 %169, label %170, label %192
170: ; preds = %164
%171 = load i32, i32* %4
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %172
%174 = load i8, i8* %173
%175 = sext i8 %174 to i32
%176 = icmp sge i32 %175, 48
br i1 %176, label %177, label %185
177: ; preds = %170
%178 = load i32, i32* %4
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %179
%181 = load i8, i8* %180
%182 = sext i8 %181 to i32
%183 = icmp sle i32 %182, 57
br i1 %183, label %184, label %185
184: ; preds = %177
store i32 1, i32* %6
br label %188
185: ; preds = %177, %170
store i32 0, i32* %6
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.16, i64 0, i64 0))
br label %192
188: ; preds = %184
br label %189
189: ; preds = %188
%190 = load i32, i32* %4
%191 = add nsw i32 %190, 1
store i32 %191, i32* %4
br label %164
192: ; preds = %185, %164
%193 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%194 = call i32 @atoi(i8* %193)
store i32 %194, i32* %5
%195 = load i32, i32* %6
%196 = icmp eq i32 %195, 1
br i1 %196, label %197, label %217
197: ; preds = %192
%198 = load i32, i32* %5
store i32 %198, i32* %7
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %200
200: ; preds = %203, %197
%201 = load i32, i32* %7
%202 = icmp sgt i32 %201, 1
br i1 %202, label %203, label %209
203: ; preds = %200
%204 = load i32, i32* %7
%205 = load i32, i32* %7
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0), i32 %204, i32 %205)
%207 = load i32, i32* %7
%208 = add nsw i32 %207, -1
store i32 %208, i32* %7
br label %200
209: ; preds = %200
%210 = load i32, i32* %7
%211 = load i32, i32* %7
%212 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0), i32 %210, i32 %211)
%213 = load i32, i32* %5
%214 = call i32 @sum_of_powers(i32 %213)
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0), i32 %214)
%216 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %217
217: ; preds = %209, %192
br label %221
218: ; preds = %158, %153
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.21, i64 0, i64 0))
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %221
221: ; preds = %218, %217
br label %222
222: ; preds = %221, %142
br label %223
223: ; preds = %222
br label %9
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"Please enter a command: \00"
@stdin = global i32 0
@.str.18 = [9 x i8] c"%d^%d + \00"
@.str.19 = [9 x i8] c"%d^%d = \00"
@.str.20 = [4 x i8] c"%d\0A\00"
@str.22 = [33 x i8] c"You entered an invalid command!\0A\00"
@str.25 = [35 x i8] c"Positive numbers are only allowed.\00"
@str.27 = [7 x i8] c"[quit]\00"
@str.28 = [23 x i8] c"Terminates execution.\0A\00"
@str.29 = [7 x i8] c"[help]\00"
@str.30 = [42 x i8] c"Prints a short help doc to the terminal.\0A\00"
@str.31 = [6 x i8] c"[<n>]\00"
@str.32 = [75 x i8] c"<n> is a positive number. The command will print out the sum of base n to\00"
@str.33 = [76 x i8] c"power n with the starting value of n by 1 at each summand until the value n\00"
@str.34 = [10 x i8] c"equals 1.\00"
@str.35 = [81 x i8] c"*******************************************************************************\0A\00"
@str.36 = [81 x i8] c"\0A*******************************************************************************\00"
@str.37 = [49 x i8] c"Thanks for using this sum of powers application!\00"
@str.38 = [80 x i8] c"*******************************************************************************\00"
@str.39 = [31 x i8] c"\0AYou entered an invalid entry!\00"
@str.40 = [35 x i8] c"You entered an invalid character.\0A\00"
@str.41 = [36 x i8] c"Enter \22help\22 for a list of commands\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.41, i64 0, i64 0))
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 1
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 2
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 3
br label %7
7: ; preds = %112, %0
br label %8
8: ; preds = %14, %7
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %3, i32 20, i32 %10)
%12 = call i32 @strlen(i8* %3)
%13 = icmp sgt i32 %12, 1
br i1 %13, label %15, label %14
14: ; preds = %8, %31
br label %8
15: ; preds = %8, %35
%16 = phi i64 [ %36, %35 ], [ 0, %8 ]
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 32
br i1 %19, label %35, label %20
20: ; preds = %15
%21 = add i8 %18, -97
%22 = icmp ult i8 %21, 26
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = add nsw i8 %18, -32
store i8 %24, i8* %17
br label %35
25: ; preds = %20
%26 = add i8 %18, -65
%27 = icmp ult i8 %26, 26
%28 = add i8 %18, -48
%29 = icmp ult i8 %28, 10
%30 = or i1 %27, %29
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.39, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.40, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.41, i64 0, i64 0))
br label %14
35: ; preds = %25, %15, %23
%36 = add nuw nsw i64 %16, 1
%37 = call i32 @strlen(i8* %3)
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %36, %39
br i1 %40, label %15, label %41
41: ; preds = %35
%42 = load i8, i8* %3
%43 = icmp eq i8 %42, 81
%44 = load i8, i8* %4
%45 = icmp eq i8 %44, 85
%46 = select i1 %43, i1 %45, i1 false
%47 = load i8, i8* %5
%48 = icmp eq i8 %47, 73
%49 = select i1 %46, i1 %48, i1 false
%50 = load i8, i8* %6
%51 = icmp eq i8 %50, 84
%52 = select i1 %49, i1 %51, i1 false
br i1 %52, label %113, label %53
53: ; preds = %41
%54 = icmp eq i8 %42, 72
%55 = icmp eq i8 %44, 69
%56 = select i1 %54, i1 %55, i1 false
%57 = icmp eq i8 %47, 76
%58 = select i1 %56, i1 %57, i1 false
%59 = icmp eq i8 %50, 80
%60 = select i1 %58, i1 %59, i1 false
br i1 %60, label %61, label %72
61: ; preds = %53
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.36, i64 0, i64 0))
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.27, i64 0, i64 0))
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.28, i64 0, i64 0))
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.29, i64 0, i64 0))
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.30, i64 0, i64 0))
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.31, i64 0, i64 0))
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.32, i64 0, i64 0))
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.33, i64 0, i64 0))
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.34, i64 0, i64 0))
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.35, i64 0, i64 0))
br label %112
72: ; preds = %53
%73 = add i8 %42, -48
%74 = icmp ult i8 %73, 10
br i1 %74, label %75, label %109
75: ; preds = %72
%76 = call i32 @strlen(i8* %3)
%77 = icmp sgt i32 %76, 1
br i1 %77, label %83, label %112
78: ; preds = %83
%79 = call i32 @strlen(i8* %3)
%80 = add nsw i32 %79, -1
%81 = sext i32 %80 to i64
%82 = icmp slt i64 %89, %81
br i1 %82, label %83, label %93
83: ; preds = %75, %78
%84 = phi i64 [ %89, %78 ], [ 0, %75 ]
%85 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = add i8 %86, -48
%88 = icmp ult i8 %87, 10
%89 = add nuw nsw i64 %84, 1
br i1 %88, label %78, label %90
90: ; preds = %83
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.39, i64 0, i64 0))
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.25, i64 0, i64 0))
br label %112
93: ; preds = %78
%94 = call i32 @atoi(i8* %3)
br i1 %77, label %95, label %112
95: ; preds = %93
%96 = call i32 @putchar(i32 10)
%97 = icmp sgt i32 %94, 1
br i1 %97, label %98, label %103
98: ; preds = %95, %98
%99 = phi i32 [ %101, %98 ], [ %94, %95 ]
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0), i32 %99, i32 %99)
%101 = add nsw i32 %99, -1
%102 = icmp ugt i32 %99, 2
br i1 %102, label %98, label %103
103: ; preds = %98, %95
%104 = phi i32 [ %94, %95 ], [ 1, %98 ]
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0), i32 %104, i32 %104)
%106 = call i32 @sum_of_powers(i32 %94)
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0), i32 %106)
%108 = call i32 @putchar(i32 10)
br label %112
109: ; preds = %72
%110 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.22, i64 0, i64 0))
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.41, i64 0, i64 0))
br label %112
112: ; preds = %75, %90, %109, %61, %103, %93
br label %7
113: ; preds = %41
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.36, i64 0, i64 0))
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.37, i64 0, i64 0))
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str.38, i64 0, i64 0))
ret i32 0
}