#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 */
double atof(char *);
double cos(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double sin(double);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  fprintf(stderr, "1\n");
  double (*fn)(double);
  if (argv[1][0] == 's')
    fn = sin;
  else
    fn = cos;
  fn(atof(argv[2]));
  fprintf(stderr, "2\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeba(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    116f <main+0x4f>
mov    0x2e7a(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    117a <main+0x5a>
mov    0x2e72(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
mov    -0x20(%rbp),%rax
call   *%rax
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2ea2(%rip),%r14
mov    (%r14),%edi
lea    0xec8(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rdi
cmpb   $0x73,(%rax)
jne    1153 <main+0x33>
mov    0x2e8f(%rip),%rbx
jmp    115a <main+0x3a>
mov    0x2e8e(%rip),%rbx
call   1030 <atof@plt>
call   *%rbx
mov    (%r14),%edi
lea    0xe98(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double (double)*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 115
br i1 %15, label %16, label %17
16: ; preds = %2
store double (double)* @sin, double (double)** %6
br label %18
17: ; preds = %2
store double (double)* @cos, double (double)** %6
br label %18
18: ; preds = %17, %16
%19 = load double (double)*, double (double)** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call double @atof(i8* %22)
%24 = call double %19(double %23)
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"2\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 115
%9 = select i1 %8, double (double)* @sin, double (double)* @cos
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call double @atof(i8* %11)
%13 = tail call double %9(double %12)
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}