#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*/ convert_lengths();
int /*<<< orphan*/ convert_weights();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int validate_input(int, int);
int main() {
  int user_input, scanf_return;
  do {
    printf("Conversion Menu:\n\t1. Lengths\n\t2. Weights\n\t0. Exit the "
           "program\nSelection: ");
    scanf_return = scanf("%d", &user_input);
    user_input = validate_input(user_input, scanf_return);
    switch (user_input) {
    case 0:
      printf("\nYou selected %d. This program will quit now... Bye.\n",
             user_input);
      break;
    case 1:
      printf("\nYou've selected %d. This program will convert lengths\n",
             user_input);
      convert_lengths();
      break;
    case 2:
      printf("\nYou've selected %d. This program will convert weights\n",
             user_input);
      convert_weights();
      break;
    }
  } while (user_input != 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <validate_input@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     11c3 <main+0x73>
jmp    11a1 <main+0x51>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     11d9 <main+0x89>
jmp    11b2 <main+0x62>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11f6 <main+0xa6>
jmp    120e <main+0xbe>
mov    -0x8(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120e <main+0xbe>
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <convert_lengths@plt>
jmp    120e <main+0xbe>
mov    -0x8(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <convert_weights@plt>
jmp    1213 <main+0xc3>
cmpl   $0x0,-0x8(%rbp)
jne    115f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%r14
lea    0xee1(%rip),%r15
lea    0x4(%rsp),%rbx
lea    0xf46(%rip),%r12
lea    0xf07(%rip),%r13
lea    0xeca(%rip),%rbp
jmp    11ae <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <convert_lengths@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1208 <main+0xb8>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
mov    %eax,%esi
call   1030 <validate_input@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%eax
je     11f0 <main+0xa0>
cmp    $0x1,%eax
je     1190 <main+0x40>
test   %eax,%eax
jne    11aa <main+0x5a>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a6 <main+0x56>
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <convert_weights@plt>
jmp    11a6 <main+0x56>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [74 x i8] c"Conversion Menu:\0A\091. Lengths\0A\092. Weights\0A\090. Exit the program\0ASelection: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"\0AYou selected %d. This program will quit now... Bye.\0A\00"
@.str.3 = [56 x i8] c"\0AYou've selected %d. This program will convert lengths\0A\00"
@.str.4 = [56 x i8] c"\0AYou've selected %d. This program will convert weights\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %23, %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i32 @validate_input(i32 %7, i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
switch i32 %10, label %22 [
i32 0, label %11
i32 1, label %14
i32 2, label %18
]
11: ; preds = %4
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %22
14: ; preds = %4
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 (...) @convert_lengths()
br label %22
18: ; preds = %4
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @convert_weights()
br label %22
22: ; preds = %4, %18, %14, %11
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %4, label %26
26: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [74 x i8] c"Conversion Menu:\0A\091. Lengths\0A\092. Weights\0A\090. Exit the program\0ASelection: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"\0AYou selected %d. This program will quit now... Bye.\0A\00"
@.str.3 = [56 x i8] c"\0AYou've selected %d. This program will convert lengths\0A\00"
@.str.4 = [56 x i8] c"\0AYou've selected %d. This program will convert weights\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %18, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, 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 %18 [
i32 0, label %8
i32 1, label %10
i32 2, label %13
]
8: ; preds = %3
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %16
10: ; preds = %3
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 1)
%12 = call i32 (...) @convert_lengths()
br label %16
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 2)
%15 = call i32 (...) @convert_weights()
br label %16
16: ; preds = %13, %10, %8
%17 = load i32, i32* %1
br label %18
18: ; preds = %16, %3
%19 = phi i32 [ %17, %16 ], [ %7, %3 ]
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %3
21: ; preds = %18
ret i32 0
}