#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 scanf(char *, int *);
int validate_input(int, int);
int /*<<< orphan*/ weight_to_metric();
int /*<<< orphan*/ weight_to_us();
void convert_weights() {
  int user_input, scanf_return;
  printf("Would you like to go convert from:\n");
  printf("\t 1. Pounds/Ounces to Kilograms/Grams\n\t 2. Kilograms/Grams to "
         "Pounds/Ounces\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:
    weight_to_metric();
    break;
  case 2:
    weight_to_us();
    break;
  }
}


x86 assembly (clang, -O0):
<convert_weights>:
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    0xf13(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <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_weights+0x76>
jmp    11a4 <convert_weights+0x54>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     11cb <convert_weights+0x7b>
jmp    11b5 <convert_weights+0x65>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     11d7 <convert_weights+0x87>
jmp    11de <convert_weights+0x8e>
jmp    11de <convert_weights+0x8e>
mov    $0x0,%al
call   1060 <weight_to_metric@plt>
jmp    11de <convert_weights+0x8e>
mov    $0x0,%al
call   1050 <weight_to_us@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_weights>:
push   %rax
lea    0xf01(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
lea    0xee6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
mov    %eax,%esi
call   1030 <validate_input@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%eax
je     11ac <convert_weights+0x4c>
cmp    $0x1,%eax
jne    11b3 <convert_weights+0x53>
xor    %eax,%eax
call   1070 <weight_to_metric@plt>
pop    %rax
ret
xor    %eax,%eax
call   1060 <weight_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 = [102 x i8] c"\09 1. Pounds/Ounces to Kilograms/Grams\0A\09 2. Kilograms/Grams to Pounds/Ounces\0A\09 0. Go back\0A Selection: \00"
@.str.2 = [3 x i8] c"%d\00"
define void @convert_weights() {
%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 ([102 x i8], [102 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 (...) @weight_to_metric()
br label %15
13: ; preds = %0
%14 = call i32 (...) @weight_to_us()
br label %15
15: ; preds = %0, %13, %11, %10
ret void
}

LLVM IR (-O2):
@.str.1 = [102 x i8] c"\09 1. Pounds/Ounces to Kilograms/Grams\0A\09 2. Kilograms/Grams to Pounds/Ounces\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_weights() {
%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 ([102 x i8], [102 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 (...) @weight_to_metric()
br label %12
10: ; preds = %0
%11 = call i32 (...) @weight_to_us()
br label %12
12: ; preds = %0, %10, %8
ret void
}