#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 */
char getch();
int /*<<< orphan*/ printw(char *, ...);
int readHcsr04();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ timeout(int);
int getUsSetpoint() {
  float cm;
  char key;
  int us;
  timeout(100);
  printw("Press Enter for setup setpoint\n\r");
  do {
    us = readHcsr04();
    cm = (float)us / 58;
    printw("%0.1f cm       \r", cm);
    refresh();
    key = getch();
  } while (key != 10);
  printw("Selected setpoint is %0.1f cm, %d us\n\n\r", (float)us / 58, us);
  return us;
}


x86 assembly (clang, -O0):
<getUsSetpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x64,%edi
call   1030 <timeout@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
mov    $0x0,%al
call   1040 <readHcsr04@plt>
mov    %eax,-0xc(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  0xe79(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe85(%rip),%rdi
mov    $0x1,%al
call   1050 <printw@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1170 <getUsSetpoint+0x20>
cvtsi2ssl -0xc(%rbp),%xmm0
movss  0xe2e(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0xc(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1050 <printw@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUsSetpoint>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%edi
call   1030 <timeout@plt>
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1050 <printw@plt>
lea    0xeb2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <readHcsr04@plt>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe68(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1050 <printw@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0xa,%al
jne    1180 <getUsSetpoint+0x30>
lea    0xe72(%rip),%rdi
movsd  (%rsp),%xmm0
mov    %ebx,%esi
mov    $0x1,%al
call   1050 <printw@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Press Enter for setup setpoint\0A\0D\00"
@.str.1 = [17 x i8] c"%0.1f cm \0D\00"
@.str.2 = [40 x i8] c"Selected setpoint is %0.1f cm, %d us\0A\0A\0D\00"
define i32 @getUsSetpoint() {
%1 = alloca float
%2 = alloca i8
%3 = alloca i32
%4 = call i32 @timeout(i32 100)
%5 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %16, %0
%7 = call i32 (...) @readHcsr04()
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = sitofp i32 %8 to float
%10 = fdiv float %9, 5.800000e+01
store float %10, float* %1
%11 = load float, float* %1
%12 = fpext float %11 to double
%13 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %12)
%14 = call i32 (...) @refresh()
%15 = call signext i8 (...) @getch()
store i8 %15, i8* %2
br label %16
16: ; preds = %6
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %6, label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to float
%23 = fdiv float %22, 5.800000e+01
%24 = fpext float %23 to double
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %24, i32 %25)
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [33 x i8] c"Press Enter for setup setpoint\0A\0D\00"
@.str.1 = [17 x i8] c"%0.1f cm \0D\00"
@.str.2 = [40 x i8] c"Selected setpoint is %0.1f cm, %d us\0A\0A\0D\00"
define i32 @getUsSetpoint() {
%1 = tail call i32 @timeout(i32 100)
%2 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %3, %0
%4 = tail call i32 (...) @readHcsr04()
%5 = sitofp i32 %4 to float
%6 = fdiv float %5, 5.800000e+01
%7 = fpext float %6 to double
%8 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %7)
%9 = tail call i32 (...) @refresh()
%10 = tail call signext i8 (...) @getch()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %7, i32 %4)
ret i32 %4
}