#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 */
struct node *deletenode(int, struct node *);
struct node *insertnode(int, int, struct node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printnode(struct node *);
int /*<<< orphan*/ printnode_reverse(struct node *);
int /*<<< orphan*/ puts(char *);
int rand();
struct node *reverse_list(struct node *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  struct node *head = NULL;
  int val, len, usrEnt, pos;
  printf("Enter How Many elements you want in Your Linked List. \n");
  scanf(" %d", &len);
  puts("Generating Your Linked List ...");
  for (pos = 1; pos <= len; pos++) {
    val = rand() % 10;
    head = insertnode(val, pos, head);
  }
  printnode(head);
  puts("What You want to Do with Your list?");
  puts("Press 1 to Delete a node");
  puts("Press 2 to Reverse This List");
  puts("Press 3 to see your list in reverse order (without reversing it)");
  puts("Press 4 to exit.");
  scanf(" %d", &usrEnt);
  pos = 0;
  if (usrEnt == 1) {
    puts("Please Enter Position You want to delete.");
    scanf(" %d", &pos);
    head = deletenode(pos, head);
    printnode(head);
    return 0;
  } else if (usrEnt == 2) {
    puts("Reversing your List...");
    head = reverse_list(head);
    printnode(head);
    return 0;
  } else if (usrEnt == 3) {
    printf("Your List is : ");
    printnode_reverse(head);
    return 0;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe52(%rip),%rdi
call   1060 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <scanf@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1215 <main+0x85>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <insertnode@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <main+0x46>
mov    -0x10(%rbp),%rdi
call   10a0 <printnode@plt>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd7(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <scanf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    12bc <main+0x12c>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    0xdaa(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <deletenode@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <printnode@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x196>
cmpl   $0x2,-0x1c(%rbp)
jne    12f4 <main+0x164>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1070 <reverse_list@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <printnode@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x196>
cmpl   $0x3,-0x1c(%rbp)
jne    131f <main+0x18f>
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <printnode_reverse@plt>
movl   $0x0,-0x4(%rbp)
jmp    1326 <main+0x196>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xf84(%rip),%rdi
call   1030 <puts@plt>
lea    0xe57(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1090 <scanf@plt>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x10(%rsp)
jle    120d <main+0x7d>
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <insertnode@plt>
mov    %rax,%rbx
cmp    0x10(%rsp),%ebp
jl     11d0 <main+0x40>
jmp    120f <main+0x7f>
xor    %ebx,%ebx
mov    %rbx,%rdi
call   10a0 <printnode@plt>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
lea    0xda6(%rip),%rdi
lea    0x14(%rsp),%rsi
call   1090 <scanf@plt>
movl   $0x0,0xc(%rsp)
mov    0x14(%rsp),%eax
cmp    $0x3,%eax
je     12aa <main+0x11a>
cmp    $0x2,%eax
je     12c0 <main+0x130>
cmp    $0x1,%eax
jne    12dc <main+0x14c>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xd6e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1080 <deletenode@plt>
jmp    12d4 <main+0x144>
lea    0xe60(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <printnode_reverse@plt>
jmp    12dc <main+0x14c>
lea    0xe33(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <reverse_list@plt>
mov    %rax,%rdi
call   10a0 <printnode@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [56 x i8] c"Enter How Many elements you want in Your Linked List. \0A\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [32 x i8] c"Generating Your Linked List ...\00"
@.str.3 = [36 x i8] c"What You want to Do with Your list?\00"
@.str.4 = [25 x i8] c"Press 1 to Delete a node\00"
@.str.5 = [29 x i8] c"Press 2 to Reverse This List\00"
@.str.6 = [65 x i8] c"Press 3 to see your list in reverse order (without reversing it)\00"
@.str.7 = [17 x i8] c"Press 4 to exit.\00"
@.str.8 = [42 x i8] c"Please Enter Position You want to delete.\00"
@.str.9 = [23 x i8] c"Reversing your List...\00"
@.str.10 = [16 x i8] c"Your List is : \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.node*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store %struct.node* null, %struct.node** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%9 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 10
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = load i32, i32* %6
%19 = load %struct.node*, %struct.node** %2
%20 = call %struct.node* @insertnode(i32 %17, i32 %18, %struct.node* %19)
store %struct.node* %20, %struct.node** %2
br label %21
21: ; preds = %14
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %10
24: ; preds = %10
%25 = load %struct.node*, %struct.node** %2
%26 = call i32 @printnode(%struct.node* %25)
%27 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @puts(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 0, i32* %6
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %43
35: ; preds = %24
%36 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%38 = load i32, i32* %6
%39 = load %struct.node*, %struct.node** %2
%40 = call %struct.node* @deletenode(i32 %38, %struct.node* %39)
store %struct.node* %40, %struct.node** %2
%41 = load %struct.node*, %struct.node** %2
%42 = call i32 @printnode(%struct.node* %41)
store i32 0, i32* %1
br label %60
43: ; preds = %24
%44 = load i32, i32* %5
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%48 = load %struct.node*, %struct.node** %2
%49 = call %struct.node* @reverse_list(%struct.node* %48)
store %struct.node* %49, %struct.node** %2
%50 = load %struct.node*, %struct.node** %2
%51 = call i32 @printnode(%struct.node* %50)
store i32 0, i32* %1
br label %60
52: ; preds = %43
%53 = load i32, i32* %5
%54 = icmp eq i32 %53, 3
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%57 = load %struct.node*, %struct.node** %2
%58 = call i32 @printnode_reverse(%struct.node* %57)
store i32 0, i32* %1
br label %60
59: ; preds = %52
store i32 0, i32* %1
br label %60
60: ; preds = %59, %55, %46, %35
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [32 x i8] c"Generating Your Linked List ...\00"
@.str.3 = [36 x i8] c"What You want to Do with Your list?\00"
@.str.4 = [25 x i8] c"Press 1 to Delete a node\00"
@.str.5 = [29 x i8] c"Press 2 to Reverse This List\00"
@.str.6 = [65 x i8] c"Press 3 to see your list in reverse order (without reversing it)\00"
@.str.7 = [17 x i8] c"Press 4 to exit.\00"
@.str.8 = [42 x i8] c"Please Enter Position You want to delete.\00"
@.str.9 = [23 x i8] c"Reversing your List...\00"
@.str.10 = [16 x i8] c"Your List is : \00"
@str = [55 x i8] c"Enter How Many elements you want in Your Linked List. \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %21, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %18, %12 ], [ 1, %0 ]
%14 = phi %struct.node* [ %17, %12 ], [ null, %0 ]
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 10
%17 = call %struct.node* @insertnode(i32 %16, i32 %13, %struct.node* %14)
%18 = add nuw nsw i32 %13, 1
%19 = load i32, i32* %1
%20 = icmp slt i32 %13, %19
br i1 %20, label %12, label %21
21: ; preds = %12, %0
%22 = phi %struct.node* [ null, %0 ], [ %17, %12 ]
%23 = call i32 @printnode(%struct.node* %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
%30 = load i32, i32* %2
switch i32 %30, label %44 [
i32 1, label %31
i32 2, label %37
i32 3, label %41
]
31: ; preds = %21
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
%35 = call %struct.node* @deletenode(i32 %34, %struct.node* %22)
%36 = call i32 @printnode(%struct.node* %35)
br label %44
37: ; preds = %21
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%39 = call %struct.node* @reverse_list(%struct.node* %22)
%40 = call i32 @printnode(%struct.node* %39)
br label %44
41: ; preds = %21
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%43 = call i32 @printnode_reverse(%struct.node* %22)
br label %44
44: ; preds = %21, %41, %37, %31
ret i32 0
}