#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*/ exp(double);
double pop();
int /*<<< orphan*/ pow(double, double);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ push(int /*<<< orphan*/);
int /*<<< orphan*/ sin(double);
scalar_t__ strrindex(char *, char *);
void mathfunc(char s[]) {
  int index;
  if (0 == strrindex(s, "sin")) {
    push(sin(pop()));
    return;
  }
  if (0 == strrindex(s, "exp")) {
    push(exp(pop()));
    return;
  }
  if (0 == strrindex(s, "pow")) {
    double ey = pop();
    push(pow(pop(), ey));
    return;
  }
  printf("error: unknown func %s\n", s);
  return;
}


x86 assembly (clang, -O0):
<mathfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strrindex@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11b2 <mathfunc+0x42>
mov    $0x0,%al
call   1050 <pop@plt>
call   1060 <sin@plt>
mov    %eax,%edi
call   1080 <push@plt>
jmp    123f <mathfunc+0xcf>
mov    -0x8(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1040 <strrindex@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e8 <mathfunc+0x78>
mov    $0x0,%al
call   1050 <pop@plt>
call   1070 <exp@plt>
mov    %eax,%edi
call   1080 <push@plt>
jmp    123f <mathfunc+0xcf>
mov    -0x8(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1040 <strrindex@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    122f <mathfunc+0xbf>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
movsd  -0x18(%rbp),%xmm1
call   1090 <pow@plt>
mov    %eax,%edi
call   1080 <push@plt>
jmp    123f <mathfunc+0xcf>
mov    -0x8(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mathfunc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xe81(%rip),%rsi
call   1040 <strrindex@plt>
test   %rax,%rax
je     11c5 <mathfunc+0x55>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strrindex@plt>
test   %rax,%rax
je     11d3 <mathfunc+0x63>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strrindex@plt>
test   %rax,%rax
je     11e1 <mathfunc+0x71>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>
xor    %eax,%eax
call   1050 <pop@plt>
call   1060 <sin@plt>
jmp    1200 <mathfunc+0x90>
xor    %eax,%eax
call   1050 <pop@plt>
call   1070 <exp@plt>
jmp    1200 <mathfunc+0x90>
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
movsd  0x8(%rsp),%xmm1
call   1090 <pow@plt>
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1080 <push@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"sin\00"
@.str.1 = [4 x i8] c"exp\00"
@.str.2 = [4 x i8] c"pow\00"
@.str.3 = [24 x i8] c"error: unknown func %s\0A\00"
define void @mathfunc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strrindex(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 0, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call double (...) @pop()
%10 = call i32 @sin(double %9)
%11 = call i32 @push(i32 %10)
br label %33
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i64 @strrindex(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 0, %14
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call double (...) @pop()
%18 = call i32 @exp(double %17)
%19 = call i32 @push(i32 %18)
br label %33
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = call i64 @strrindex(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 0, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = call double (...) @pop()
store double %25, double* %4
%26 = call double (...) @pop()
%27 = load double, double* %4
%28 = call i32 @pow(double %26, double %27)
%29 = call i32 @push(i32 %28)
br label %33
30: ; preds = %20
%31 = load i8*, i8** %2
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %24, %16, %8
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"sin\00"
@.str.1 = [4 x i8] c"exp\00"
@.str.2 = [4 x i8] c"pow\00"
@.str.3 = [24 x i8] c"error: unknown func %s\0A\00"
define void @mathfunc(i8* %0) {
%2 = tail call i64 @strrindex(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call double (...) @pop()
%6 = tail call i32 @sin(double %5)
%7 = tail call i32 @push(i32 %6)
br label %25
8: ; preds = %1
%9 = tail call i64 @strrindex(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = tail call double (...) @pop()
%13 = tail call i32 @exp(double %12)
%14 = tail call i32 @push(i32 %13)
br label %25
15: ; preds = %8
%16 = tail call i64 @strrindex(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = tail call double (...) @pop()
%20 = tail call double (...) @pop()
%21 = tail call i32 @pow(double %20, double %19)
%22 = tail call i32 @push(i32 %21)
br label %25
23: ; preds = %15
%24 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %23, %18, %11, %4
ret void
}