#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 EOF;
double exp(double);
int getchar();
double pop();
double pow(double, double);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
scalar_t__ strcmp(char *, char *);
void math_funcs(void) {
  double op2;
  char s[10];
  int c, i = 0;
  printf("\t\tSpecial function to trigonometry:\nCommands: sin, exp, pow\n");
  while ((c = getchar()) != '\n' && c != EOF)
    s[i++] = c;
  s[i] = '\0';
  if (strcmp(s, "sin") == 0)
    printf("%.8g\n", sin(pop()));
  else if (strcmp(s, "exp") == 0)
    printf("%.8g\n", exp(pop()));
  else if (strcmp(s, "pow") == 0) {
    op2 = pop();
    printf("%.8g\n", pow(pop(), op2));
  } else
    printf("Wrong command\n");
}


x86 assembly (clang, -O0):
<math_funcs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x1c(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1d(%rbp)
je     11b9 <math_funcs+0x49>
mov    -0x18(%rbp),%eax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11c9 <math_funcs+0x59>
jmp    11e4 <math_funcs+0x74>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %cl,-0x12(%rbp,%rax,1)
jmp    118d <math_funcs+0x1d>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x12(%rbp,%rax,1)
lea    -0x12(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1226 <math_funcs+0xb6>
mov    $0x0,%al
call   1040 <pop@plt>
call   1070 <sin@plt>
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12c1 <math_funcs+0x151>
lea    -0x12(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    125f <math_funcs+0xef>
mov    $0x0,%al
call   1040 <pop@plt>
call   1080 <exp@plt>
lea    0xdee(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12bc <math_funcs+0x14c>
lea    -0x12(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <math_funcs+0x139>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movsd  -0x8(%rbp),%xmm1
call   1090 <pow@plt>
lea    0xda4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12b7 <math_funcs+0x147>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bc <math_funcs+0x14c>
jmp    12c1 <math_funcs+0x151>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_funcs>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
je     11cb <math_funcs+0x4b>
mov    0x2e40(%rip),%r14
cmp    (%r14),%eax
je     11cb <math_funcs+0x4b>
xor    %ebx,%ebx
nop
mov    %al,0x6(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
je     11c9 <math_funcs+0x49>
cmp    (%r14),%eax
jne    11b0 <math_funcs+0x30>
mov    %ebx,%ebx
movb   $0x0,0x6(%rsp,%rbx,1)
lea    0xe29(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1220 <math_funcs+0xa0>
lea    0xe1d(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     122e <math_funcs+0xae>
lea    0xe43(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123c <math_funcs+0xbc>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
jmp    1269 <math_funcs+0xe9>
xor    %eax,%eax
call   1050 <pop@plt>
call   1080 <sin@plt>
jmp    125b <math_funcs+0xdb>
xor    %eax,%eax
call   1050 <pop@plt>
call   1090 <exp@plt>
jmp    125b <math_funcs+0xdb>
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
movsd  0x10(%rsp),%xmm1
call   10a0 <pow@plt>
lea    0xda2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [61 x i8] c"\09\09Special function to trigonometry:\0ACommands: sin, exp, pow\0A\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"sin\00"
@.str.2 = [6 x i8] c"%.8g\0A\00"
@.str.3 = [4 x i8] c"exp\00"
@.str.4 = [4 x i8] c"pow\00"
@.str.5 = [15 x i8] c"Wrong command\0A\00"
define void @math_funcs() {
%1 = alloca double
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %15, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %3
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %22
15: ; preds = %13
%16 = load i32, i32* %3
%17 = trunc i32 %16 to i8
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %20
store i8 %17, i8* %21
br label %6
22: ; preds = %13
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = call double (...) @pop()
%31 = call double @sin(double %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %31)
br label %55
33: ; preds = %22
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = call double (...) @pop()
%39 = call double @exp(double %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %39)
br label %54
41: ; preds = %33
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = call double (...) @pop()
store double %46, double* %1
%47 = call double (...) @pop()
%48 = load double, double* %1
%49 = call double @pow(double %47, double %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %49)
br label %53
51: ; preds = %41
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %45
br label %54
54: ; preds = %53, %37
br label %55
55: ; preds = %54, %29
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [4 x i8] c"sin\00"
@.str.2 = [6 x i8] c"%.8g\0A\00"
@.str.3 = [4 x i8] c"exp\00"
@.str.4 = [4 x i8] c"pow\00"
@str = [60 x i8] c"\09\09Special function to trigonometry:\0ACommands: sin, exp, pow\00"
@str.6 = [14 x i8] c"Wrong command\00"
define void @math_funcs() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @getchar()
%5 = icmp ne i32 %4, 10
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %4, %6
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %22
9: ; preds = %0, %9
%10 = phi i64 [ %13, %9 ], [ 0, %0 ]
%11 = phi i32 [ %15, %9 ], [ %4, %0 ]
%12 = trunc i32 %11 to i8
%13 = add nuw i64 %10, 1
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %10
store i8 %12, i8* %14
%15 = tail call i32 (...) @getchar()
%16 = icmp ne i32 %15, 10
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %9, label %20
20: ; preds = %9
%21 = and i64 %13, 4294967295
br label %22
22: ; preds = %20, %0
%23 = phi i64 [ 0, %0 ], [ %21, %20 ]
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %23
store i8 0, i8* %24
%25 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = call double (...) @pop()
%29 = call double @sin(double %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %29)
br label %48
31: ; preds = %22
%32 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = call double (...) @pop()
%36 = call double @exp(double %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %36)
br label %48
38: ; preds = %31
%39 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = call double (...) @pop()
%43 = call double (...) @pop()
%44 = call double @pow(double %43, double %42)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %44)
br label %48
46: ; preds = %38
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %48
48: ; preds = %34, %46, %41, %27
ret void
}