#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 const sin(double const);
double get_scale_factor(const double *x, int dim) {
  if (dim == 0)
    return x[0] * sin(x[2]);
  else if (dim == 2)
    return x[0];
  return 1.0;
}


x86 assembly (clang, -O0):
<get_scale_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115a <get_scale_factor+0x4a>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1188 <get_scale_factor+0x78>
cmpl   $0x2,-0x14(%rbp)
jne    1176 <get_scale_factor+0x66>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1188 <get_scale_factor+0x78>
jmp    117b <get_scale_factor+0x6b>
movsd  0xe7d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_scale_factor>:
push   %rax
cmp    $0x2,%esi
je     1134 <get_scale_factor+0x24>
test   %esi,%esi
jne    113a <get_scale_factor+0x2a>
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rdi),%xmm0
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret
movsd  (%rdi),%xmm0
pop    %rax
ret
movsd  0xebe(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @get_scale_factor(double* %0, i32 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load double*, double** %4
%10 = getelementptr inbounds double, double* %9, i64 0
%11 = load double, double* %10
%12 = load double*, double** %4
%13 = getelementptr inbounds double, double* %12, i64 2
%14 = load double, double* %13
%15 = call double @sin(double %14)
%16 = fmul double %11, %15
store double %16, double* %3
br label %26
17: ; preds = %2
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load double*, double** %4
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
store double %23, double* %3
br label %26
24: ; preds = %17
br label %25
25: ; preds = %24
store double 1.000000e+00, double* %3
br label %26
26: ; preds = %25, %20, %8
%27 = load double, double* %3
ret double %27
}

LLVM IR (-O2):
define double @get_scale_factor(double* nocapture %0, i32 %1) {
switch i32 %1, label %11 [
i32 0, label %3
i32 2, label %9
]
3: ; preds = %2
%4 = load double, double* %0
%5 = getelementptr inbounds double, double* %0, i64 2
%6 = load double, double* %5
%7 = tail call double @sin(double %6)
%8 = fmul double %4, %7
br label %11
9: ; preds = %2
%10 = load double, double* %0
br label %11
11: ; preds = %2, %9, %3
%12 = phi double [ %8, %3 ], [ %10, %9 ], [ 1.000000e+00, %2 ]
ret double %12
}