#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 /*<<< orphan*/ getch();
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;
  getch();
  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)
mov    $0x0,%al
call   1090 <getch@plt>
lea    0xe63(%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     11d0 <math_funcs+0x50>
mov    -0x18(%rbp),%eax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e0 <math_funcs+0x60>
jmp    11fb <math_funcs+0x7b>
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    11a4 <math_funcs+0x24>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x12(%rbp,%rax,1)
lea    -0x12(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123d <math_funcs+0xbd>
mov    $0x0,%al
call   1040 <pop@plt>
call   1070 <sin@plt>
lea    0xe10(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12d8 <math_funcs+0x158>
lea    -0x12(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <math_funcs+0xf6>
mov    $0x0,%al
call   1040 <pop@plt>
call   1080 <exp@plt>
lea    0xdd7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12d3 <math_funcs+0x153>
lea    -0x12(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12c0 <math_funcs+0x140>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movsd  -0x8(%rbp),%xmm1
call   10a0 <pow@plt>
lea    0xd8d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ce <math_funcs+0x14e>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d3 <math_funcs+0x153>
jmp    12d8 <math_funcs+0x158>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_funcs>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   10a0 <getch@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
je     11ec <math_funcs+0x5c>
mov    0x2e26(%rip),%r15
cmp    (%r15),%eax
je     11ec <math_funcs+0x5c>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %al,0xe(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
je     11e9 <math_funcs+0x59>
cmp    (%r15),%eax
jne    11d0 <math_funcs+0x40>
mov    %ebx,%r14d
movb   $0x0,0xe(%rsp,%r14,1)
lea    0xe07(%rip),%rsi
lea    0xe(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1242 <math_funcs+0xb2>
lea    0xdfb(%rip),%rsi
lea    0xe(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1250 <math_funcs+0xc0>
lea    0xe21(%rip),%rsi
lea    0xe(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     125e <math_funcs+0xce>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
jmp    128b <math_funcs+0xfb>
xor    %eax,%eax
call   1050 <pop@plt>
call   1080 <sin@plt>
jmp    127d <math_funcs+0xed>
xor    %eax,%eax
call   1050 <pop@plt>
call   1090 <exp@plt>
jmp    127d <math_funcs+0xed>
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
movsd  0x18(%rsp),%xmm1
call   10b0 <pow@plt>
lea    0xd80(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 (...) @getch()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %16, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %3
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = load i32, i32* %3
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %21
store i8 %18, i8* %22
br label %7
23: ; preds = %14
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = call double (...) @pop()
%32 = call double @sin(double %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %56
34: ; preds = %23
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call double (...) @pop()
%40 = call double @exp(double %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %55
42: ; preds = %34
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = call double (...) @pop()
store double %47, double* %1
%48 = call double (...) @pop()
%49 = load double, double* %1
%50 = call double @pow(double %48, double %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %50)
br label %54
52: ; preds = %42
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %46
br label %55
55: ; preds = %54, %38
br label %56
56: ; preds = %55, %30
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 (...) @getch()
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (...) @getchar()
%6 = icmp ne i32 %5, 10
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %5, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %23
10: ; preds = %0, %10
%11 = phi i64 [ %14, %10 ], [ 0, %0 ]
%12 = phi i32 [ %16, %10 ], [ %5, %0 ]
%13 = trunc i32 %12 to i8
%14 = add nuw i64 %11, 1
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %11
store i8 %13, i8* %15
%16 = tail call i32 (...) @getchar()
%17 = icmp ne i32 %16, 10
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %10, label %21
21: ; preds = %10
%22 = and i64 %14, 4294967295
br label %23
23: ; preds = %21, %0
%24 = phi i64 [ 0, %0 ], [ %22, %21 ]
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = call double (...) @pop()
%30 = call double @sin(double %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %49
32: ; preds = %23
%33 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = call double (...) @pop()
%37 = call double @exp(double %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %37)
br label %49
39: ; preds = %32
%40 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = call double (...) @pop()
%44 = call double (...) @pop()
%45 = call double @pow(double %44, double %43)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %45)
br label %49
47: ; preds = %39
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %49
49: ; preds = %35, %47, %42, %28
ret void
}