#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  char gender;
  int haveGender = 1;
  int age;
  double weight;
  double height;
  double bmrInKj;
  double bmrInKcal;
  printf("bmrcalc can calculate your BasalMetabolicRate\nLet's start off with "
         "you telling us your gender, m(ale) or f(emale), and age (years):");
  scanf("%c%d", &gender, &age);
  while (haveGender == 1) {
    if (gender != 'm' && gender != 'f') {
      printf(
          "bmrcalc did not recognize that gender, please use m/f (lowercase):");
      scanf("%c", &gender);
      continue;
    }
    haveGender = 0;
  }
  printf("Please provide your vitals, weight (in kg), then height (in cm, "
         "decimals are supported):");
  scanf("%lf%lf", &weight, &height);
  if (gender == 'f') {
    bmrInKj = ((42 * weight) + (26.3 * height) - (20, 7 * age) - 676.2);
  } else {
    bmrInKj = ((42 * weight) + (26.3 * height) - (20, 7 * age) + 697.2 - 676.2);
  }
  bmrInKcal = bmrInKj / 4.2;
  printf("The numbers have been crunched!\nYour BMR is %lfkcal (%lfkj).\nGood "
         "health to you!\n",
         bmrInKcal, bmrInKj);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf61(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11af <main+0x8f>
movsbl -0x5(%rbp),%eax
cmp    $0x6d,%eax
je     11a3 <main+0x83>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
je     11a3 <main+0x83>
lea    0xf2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf61(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    115a <main+0x3a>
movl   $0x0,-0xc(%rbp)
jmp    115a <main+0x3a>
lea    0xf41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf8c(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jne    1224 <main+0x104>
movsd  -0x18(%rbp),%xmm0
movsd  0xe2b(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  0xe16(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
imul   $0x7,-0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xdea(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126f <main+0x14f>
movsd  -0x18(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  0xdd2(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
imul   $0x7,-0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xdae(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd9a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xec1(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xef8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf6e(%rip),%rdi
lea    0xb(%rsp),%r14
lea    0xc(%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xf58(%rip),%r15
lea    0xf94(%rip),%rbx
movzbl 0xb(%rsp),%eax
cmp    $0x66,%al
je     1186 <main+0x66>
cmp    $0x6d,%al
je     1186 <main+0x66>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
jmp    1160 <main+0x40>
lea    0xf6a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xfb5(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
lea    0x0(,%rax,8),%ecx
sub    %eax,%ecx
cmpb   $0x66,0xb(%rsp)
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  0xe2e(%rip),%xmm0
mulsd  0xe2e(%rip),%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
subsd  %xmm0,%xmm1
je     11f3 <main+0xd3>
addsd  0xe1d(%rip),%xmm1
addsd  0xe1d(%rip),%xmm1
movapd %xmm1,%xmm0
divsd  0xe19(%rip),%xmm0
lea    0xf49(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [132 x i8] c"bmrcalc can calculate your BasalMetabolicRate\0ALet's start off with you telling us your gender, m(ale) or f(emale), and age (years):\00"
@.str.1 = [5 x i8] c"%c%d\00"
@.str.2 = [67 x i8] c"bmrcalc did not recognize that gender, please use m/f (lowercase):\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [89 x i8] c"Please provide your vitals, weight (in kg), then height (in cm, decimals are supported):\00"
@.str.5 = [7 x i8] c"%lf%lf\00"
@.str.6 = [82 x i8] c"The numbers have been crunched!\0AYour BMR is %lfkcal (%lfkj).\0AGood health to you!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
store i32 1, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32* %4)
br label %11
11: ; preds = %25, %22, %0
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 109
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 102
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %11
25: ; preds = %18, %14
store i32 0, i32* %3
br label %11
26: ; preds = %11
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double* %5, double* %6)
%29 = load i8, i8* %2
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 102
br i1 %31, label %32, label %42
32: ; preds = %26
%33 = load double, double* %5
%34 = load double, double* %6
%35 = fmul double 2.630000e+01, %34
%36 = call double @llvm.fmuladd.f64(double 4.200000e+01, double %33, double %35)
%37 = load i32, i32* %4
%38 = mul nsw i32 7, %37
%39 = sitofp i32 %38 to double
%40 = fsub double %36, %39
%41 = fsub double %40, 6.762000e+02
store double %41, double* %7
br label %53
42: ; preds = %26
%43 = load double, double* %5
%44 = load double, double* %6
%45 = fmul double 2.630000e+01, %44
%46 = call double @llvm.fmuladd.f64(double 4.200000e+01, double %43, double %45)
%47 = load i32, i32* %4
%48 = mul nsw i32 7, %47
%49 = sitofp i32 %48 to double
%50 = fsub double %46, %49
%51 = fadd double %50, 6.972000e+02
%52 = fsub double %51, 6.762000e+02
store double %52, double* %7
br label %53
53: ; preds = %42, %32
%54 = load double, double* %7
%55 = fdiv double %54, 4.200000e+00
store double %55, double* %8
%56 = load double, double* %8
%57 = load double, double* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0), double %56, double %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [132 x i8] c"bmrcalc can calculate your BasalMetabolicRate\0ALet's start off with you telling us your gender, m(ale) or f(emale), and age (years):\00"
@.str.1 = [5 x i8] c"%c%d\00"
@.str.2 = [67 x i8] c"bmrcalc did not recognize that gender, please use m/f (lowercase):\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [89 x i8] c"Please provide your vitals, weight (in kg), then height (in cm, decimals are supported):\00"
@.str.5 = [7 x i8] c"%lf%lf\00"
@.str.6 = [82 x i8] c"The numbers have been crunched!\0AYour BMR is %lfkcal (%lfkj).\0AGood health to you!\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = bitcast i32* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32* %2)
br label %10
10: ; preds = %12, %0
%11 = load i8, i8* %1
switch i8 %11, label %12 [
i8 109, label %15
i8 102, label %15
]
12: ; preds = %10
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %10
15: ; preds = %10, %10
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double* %3, double* %4)
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 102
%20 = load double, double* %3
%21 = load double, double* %4
%22 = fmul double %21, 2.630000e+01
%23 = call double @llvm.fmuladd.f64(double %20, double 4.200000e+01, double %22)
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, 7
%26 = sitofp i32 %25 to double
%27 = fsub double %23, %26
%28 = fadd double %27, 6.972000e+02
%29 = select i1 %19, double %27, double %28
%30 = fadd double %29, -6.762000e+02
%31 = fdiv double %30, 4.200000e+00
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0), double %31, double %30)
ret i32 0
}