#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 */
struct node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ print_colors(struct node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
struct node *sort_ascending(struct node *);
struct node *sort_decending(struct node *);
struct node *sort_menu(struct node *head) {
  char sorting_choice[2];
  printf("\nWould you like to sort in Ascending, Decending or Neither? "
         "\n(a/d/n) ");
  scanf("%s", sorting_choice);
  if (sorting_choice[0] == 'a') {
    printf("\n\n");
    head = sort_ascending(head);
  } else if (sorting_choice[0] == 'd') {
    printf("\n\n");
    head = sort_decending(head);
  }
  printf("\nSorted:\n");
  print_colors(head);
  return head;
}


x86 assembly (clang, -O0):
<sort_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
lea    -0xa(%rbp),%rsi
lea    0xed3(%rip),%rdi
call   1070 <scanf@plt>
movsbl -0xa(%rbp),%eax
cmp    $0x61,%eax
jne    11a3 <sort_menu+0x53>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sort_ascending@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <sort_menu+0x7e>
movsbl -0xa(%rbp),%eax
cmp    $0x64,%eax
jne    11c9 <sort_menu+0x79>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <sort_decending@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <sort_menu+0x7e>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <print_colors@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_menu>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xe(%rsp),%al
cmp    $0x64,%al
je     11a7 <sort_menu+0x47>
cmp    $0x61,%al
jne    11be <sort_menu+0x5e>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <sort_ascending@plt>
jmp    11bb <sort_menu+0x5b>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <sort_decending@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <print_colors@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [70 x i8] c"\0AWould you like to sort in Ascending, Decending or Neither? \0A(a/d/n) \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [10 x i8] c"\0ASorted:\0A\00"
define %struct.node* @sort_menu(%struct.node* %0) {
%2 = alloca %struct.node*
%3 = alloca [2 x i8]
store %struct.node* %0, %struct.node** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 97
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = load %struct.node*, %struct.node** %2
%14 = call %struct.node* @sort_ascending(%struct.node* %13)
store %struct.node* %14, %struct.node** %2
br label %25
15: ; preds = %1
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = load %struct.node*, %struct.node** %2
%23 = call %struct.node* @sort_decending(%struct.node* %22)
store %struct.node* %23, %struct.node** %2
br label %24
24: ; preds = %20, %15
br label %25
25: ; preds = %24, %11
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%27 = load %struct.node*, %struct.node** %2
%28 = call i32 @print_colors(%struct.node* %27)
%29 = load %struct.node*, %struct.node** %2
ret %struct.node* %29
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [70 x i8] c"\0AWould you like to sort in Ascending, Decending or Neither? \0A(a/d/n) \00"
@.str.1 = [3 x i8] c"%s\00"
@str = [9 x i8] c"\0ASorted:\00"
@str.5 = [2 x i8] c"\0A\00"
define %struct.node* @sort_menu(%struct.node* %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 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), i8* %3)
%6 = load i8, i8* %3
switch i8 %6, label %13 [
i8 97, label %7
i8 100, label %10
]
7: ; preds = %1
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%9 = call %struct.node* @sort_ascending(%struct.node* %0)
br label %13
10: ; preds = %1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%12 = call %struct.node* @sort_decending(%struct.node* %0)
br label %13
13: ; preds = %1, %10, %7
%14 = phi %struct.node* [ %9, %7 ], [ %12, %10 ], [ %0, %1 ]
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%16 = call i32 @print_colors(%struct.node* %14)
ret %struct.node* %14
}