#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 M_PI;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double volume(double r, int DIM) {
  if (DIM == 1) {
    return 2 * r;
  }
  if (DIM == 2) {
    return M_PI * r * r;
  }
  if (DIM == 3) {
    return 4 * M_PI * r * r * r / 3.;
  }
  fprintf(stderr, "Could not compute volume for DIM>3\n");
  return 0;
}


x86 assembly (clang, -O0):
<volume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1141 <volume+0x31>
movsd  0xede(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c9 <volume+0xb9>
cmpl   $0x2,-0x14(%rbp)
jne    116a <volume+0x5a>
mov    0x2e96(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c9 <volume+0xb9>
cmpl   $0x3,-0x14(%rbp)
jne    11ac <volume+0x9c>
movsd  0xe8c(%rip),%xmm0
mov    0x2e65(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c9 <volume+0xb9>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<volume>:
push   %rax
cmp    $0x3,%edi
je     1126 <volume+0x16>
cmp    $0x2,%edi
je     1153 <volume+0x43>
cmp    $0x1,%edi
jne    1168 <volume+0x58>
addsd  %xmm0,%xmm0
pop    %rax
ret
mov    0x2ebb(%rip),%rax
movsd  (%rax),%xmm1
mulsd  0xec7(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
divsd  0xebb(%rip),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret
mov    0x2e8e(%rip),%rax
movsd  (%rax),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm0
pop    %rax
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@stderr = global i32 0
@.str = [36 x i8] c"Could not compute volume for DIM>3\0A\00"
define double @volume(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, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load double, double* %4
%10 = fmul double 2.000000e+00, %9
store double %10, double* %3
br label %36
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load double, double* @M_PI
%16 = load double, double* %4
%17 = fmul double %15, %16
%18 = load double, double* %4
%19 = fmul double %17, %18
store double %19, double* %3
br label %36
20: ; preds = %11
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load double, double* @M_PI
%25 = fmul double 4.000000e+00, %24
%26 = load double, double* %4
%27 = fmul double %25, %26
%28 = load double, double* %4
%29 = fmul double %27, %28
%30 = load double, double* %4
%31 = fmul double %29, %30
%32 = fdiv double %31, 3.000000e+00
store double %32, double* %3
br label %36
33: ; preds = %20
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %3
br label %36
36: ; preds = %33, %23, %14, %8
%37 = load double, double* %3
ret double %37
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@stderr = global i32 0
@.str = [36 x i8] c"Could not compute volume for DIM>3\0A\00"
define double @volume(double %0, i32 %1) {
switch i32 %1, label %16 [
i32 1, label %3
i32 2, label %5
i32 3, label %9
]
3: ; preds = %2
%4 = fmul double %0, 2.000000e+00
br label %19
5: ; preds = %2
%6 = load double, double* @M_PI
%7 = fmul double %6, %0
%8 = fmul double %7, %0
br label %19
9: ; preds = %2
%10 = load double, double* @M_PI
%11 = fmul double %10, 4.000000e+00
%12 = fmul double %11, %0
%13 = fmul double %12, %0
%14 = fmul double %13, %0
%15 = fdiv double %14, 3.000000e+00
br label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %9, %5, %3
%20 = phi double [ %4, %3 ], [ %8, %5 ], [ %15, %9 ], [ 0.000000e+00, %16 ]
ret double %20
}