#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*/ clear(struct node **);
int /*<<< orphan*/ length(struct node *);
int /*<<< orphan*/ print(struct node *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(struct node **, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sort_ascending(struct node **);
int /*<<< orphan*/ sort_descending(struct node **);
int main() {
  char ans;
  int num;
  struct node *head = NULL;
  do {
    do {
      printf("Enter a number: ");
      scanf("%d", &num);
      push(&head, num);
      printf("Do you want another num (y or n): ");
      scanf("%1s", &ans);
    } while (ans == 'y');
    printf("Sort ascending or descending (a or d)? ");
    scanf("%1s", &ans);
    if (ans == 'a')
      sort_ascending(&head);
    else if (ans == 'd')
      sort_descending(&head);
    print(head, length(head));
    printf("Do you want to do this again (y or n)? ");
    scanf("%1s", &ans);
    if (ans == 'y')
      clear(&head);
  } while (ans == 'y');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    119c <main+0x1c>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1090 <push@plt>
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x79,%eax
je     119c <main+0x1c>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
lea    0xe33(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jne    122a <main+0xaa>
lea    -0x18(%rbp),%rdi
call   1070 <sort_ascending@plt>
jmp    1245 <main+0xc5>
movsbl -0x5(%rbp),%eax
cmp    $0x64,%eax
jne    1240 <main+0xc0>
lea    -0x18(%rbp),%rdi
call   1060 <sort_descending@plt>
jmp    1245 <main+0xc5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <length@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <print@plt>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
lea    0xdc3(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x79,%eax
jne    1295 <main+0x115>
lea    -0x18(%rbp),%rdi
call   10a0 <clear@plt>
jmp    129a <main+0x11a>
movsbl -0x5(%rbp),%eax
cmp    $0x79,%eax
je     1197 <main+0x17>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
lea    0xe62(%rip),%r15
lea    0xe6c(%rip),%rbx
lea    0xc(%rsp),%rbp
lea    0x10(%rsp),%r12
lea    0xe81(%rip),%r13
lea    0xb(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
call   1090 <push@plt>
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmpb   $0x79,0xb(%rsp)
je     11c0 <main+0x40>
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movzbl 0xb(%rsp),%eax
cmp    $0x64,%al
je     1231 <main+0xb1>
cmp    $0x61,%al
jne    1239 <main+0xb9>
mov    %r12,%rdi
call   1070 <sort_ascending@plt>
jmp    1239 <main+0xb9>
mov    %r12,%rdi
call   1060 <sort_descending@plt>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1030 <length@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <print@plt>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmpb   $0x79,0xb(%rsp)
lea    0xd8b(%rip),%r15
lea    0xd95(%rip),%rbx
jne    1291 <main+0x111>
mov    %r12,%rdi
call   10a0 <clear@plt>
cmpb   $0x79,0xb(%rsp)
je     11c0 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Do you want another num (y or n): \00"
@.str.3 = [4 x i8] c"%1s\00"
@.str.4 = [40 x i8] c"Sort ascending or descending (a or d)? \00"
@.str.5 = [40 x i8] c"Do you want to do this again (y or n)? \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca %struct.node*
store i32 0, i32* %1
store %struct.node* null, %struct.node** %4
br label %5
5: ; preds = %45, %0
br label %6
6: ; preds = %13, %5
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = call i32 @push(%struct.node** %4, i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %13
13: ; preds = %6
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 121
br i1 %16, label %6, label %17
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 97
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @sort_ascending(%struct.node** %4)
br label %32
25: ; preds = %17
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 100
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @sort_descending(%struct.node** %4)
br label %31
31: ; preds = %29, %25
br label %32
32: ; preds = %31, %23
%33 = load %struct.node*, %struct.node** %4
%34 = load %struct.node*, %struct.node** %4
%35 = call i32 @length(%struct.node* %34)
%36 = call i32 @print(%struct.node* %33, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%39 = load i8, i8* %2
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 121
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 @clear(%struct.node** %4)
br label %44
44: ; preds = %42, %32
br label %45
45: ; preds = %44
%46 = load i8, i8* %2
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 121
br i1 %48, label %5, label %49
49: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Do you want another num (y or n): \00"
@.str.3 = [4 x i8] c"%1s\00"
@.str.4 = [40 x i8] c"Sort ascending or descending (a or d)? \00"
@.str.5 = [40 x i8] c"Do you want to do this again (y or n)? \00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca %struct.node*
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.node** %3 to i8*
store %struct.node* null, %struct.node** %3
br label %6
6: ; preds = %15, %0
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @push(%struct.node** %3, i32 %9)
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 121
br i1 %14, label %15, label %16
15: ; preds = %6, %32
br label %6
16: ; preds = %6
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%19 = load i8, i8* %1
switch i8 %19, label %24 [
i8 97, label %20
i8 100, label %22
]
20: ; preds = %16
%21 = call i32 @sort_ascending(%struct.node** %3)
br label %24
22: ; preds = %16
%23 = call i32 @sort_descending(%struct.node** %3)
br label %24
24: ; preds = %16, %22, %20
%25 = load %struct.node*, %struct.node** %3
%26 = call i32 @length(%struct.node* %25)
%27 = call i32 @print(%struct.node* %25, i32 %26)
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%30 = load i8, i8* %1
%31 = icmp eq i8 %30, 121
br i1 %31, label %32, label %36
32: ; preds = %24
%33 = call i32 @clear(%struct.node** %3)
%34 = load i8, i8* %1
%35 = icmp eq i8 %34, 121
br i1 %35, label %15, label %36
36: ; preds = %24, %32
ret i32 0
}