#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*/ length_to_metric();
int /*<<< orphan*/ length_to_us();
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int validate_input(int, int);
void convert_lengths() {
  int user_input, scanf_return;
  printf("Would you like to go convert from:\n");
  printf("\t 1. Feet/Inches to Meters/Centimeters\n\t 2. Meters/Centimeters to "
         "Feet/Inches\n\t 0. Go back\n Selection: ");
  scanf_return = scanf("%d", &user_input);
  user_input = validate_input(user_input, scanf_return);
  switch (user_input) {
  case 0:
    break;
  case 1:
    length_to_metric();
    break;
  case 2:
    length_to_us();
    break;
  }
}


x86 assembly (clang, -O0):
<convert_lengths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1040 <printf@plt>
lea    0xf15(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <validate_input@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     11c6 <convert_lengths+0x76>
jmp    11a4 <convert_lengths+0x54>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     11cb <convert_lengths+0x7b>
jmp    11b5 <convert_lengths+0x65>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     11d7 <convert_lengths+0x87>
jmp    11de <convert_lengths+0x8e>
jmp    11de <convert_lengths+0x8e>
mov    $0x0,%al
call   1050 <length_to_metric@plt>
jmp    11de <convert_lengths+0x8e>
mov    $0x0,%al
call   1070 <length_to_us@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_lengths>:
push   %rax
lea    0xf03(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
lea    0xee8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
mov    %eax,%esi
call   1030 <validate_input@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%eax
je     11ac <convert_lengths+0x4c>
cmp    $0x1,%eax
jne    11b3 <convert_lengths+0x53>
xor    %eax,%eax
call   1060 <length_to_metric@plt>
pop    %rax
ret
xor    %eax,%eax
call   1080 <length_to_us@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Would you like to go convert from:\0A\00"
@.str.1 = [104 x i8] c"\09 1. Feet/Inches to Meters/Centimeters\0A\09 2. Meters/Centimeters to Feet/Inches\0A\09 0. Go back\0A Selection: \00"
@.str.2 = [3 x i8] c"%d\00"
define void @convert_lengths() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
store i32 %5, i32* %2
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = call i32 @validate_input(i32 %6, i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
switch i32 %9, label %15 [
i32 0, label %10
i32 1, label %11
i32 2, label %13
]
10: ; preds = %0
br label %15
11: ; preds = %0
%12 = call i32 (...) @length_to_metric()
br label %15
13: ; preds = %0
%14 = call i32 (...) @length_to_us()
br label %15
15: ; preds = %0, %13, %11, %10
ret void
}

LLVM IR (-O2):
@.str.1 = [104 x i8] c"\09 1. Feet/Inches to Meters/Centimeters\0A\09 2. Meters/Centimeters to Feet/Inches\0A\09 0. Go back\0A Selection: \00"
@.str.2 = [3 x i8] c"%d\00"
@str = [35 x i8] c"Would you like to go convert from:\00"
define void @convert_lengths() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([104 x i8], [104 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = call i32 @validate_input(i32 %6, i32 %5)
store i32 %7, i32* %1
switch i32 %7, label %12 [
i32 2, label %10
i32 1, label %8
]
8: ; preds = %0
%9 = call i32 (...) @length_to_metric()
br label %12
10: ; preds = %0
%11 = call i32 (...) @length_to_us()
br label %12
12: ; preds = %0, %10, %8
ret void
}