#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 item {
  int dummy;
};

/* Variables and functions */
int getNth(struct item *, int);
struct item *insertAtEnd(struct item *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  struct item *start = NULL;
  int choice, number, n;
  do {
    printf("1. Insert element into a linked list\n");
    printf("2. Find nth element in the linked list\n");
    printf("Enter choice\n");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      printf("Enter the number to be inserted\n");
      scanf("%d", &number);
      start = insertAtEnd(start, number);
      break;
    case 2:
      printf("Enter the value of n\n");
      scanf("%d", &n);
      number = getNth(start, n);
      printf("The %dth element in the linked list is %d\n", n, number);
      break;
    case 3:
      break;
    default:
      printf("Invalid choice\n");
    }
  } while (choice != 3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     11cc <main+0x8c>
jmp    11aa <main+0x6a>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     11ff <main+0xbf>
jmp    11bb <main+0x7b>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     1245 <main+0x105>
jmp    124a <main+0x10a>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <insertAtEnd@plt>
mov    %rax,-0x10(%rbp)
jmp    1258 <main+0x118>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe48(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <getNth@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1258 <main+0x118>
jmp    1258 <main+0x118>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125d <main+0x11d>
cmpl   $0x3,-0x14(%rbp)
jne    1157 <main+0x17>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec9(%rip),%r14
lea    0xee7(%rip),%r15
lea    0xf07(%rip),%r12
lea    0xe86(%rip),%rbx
lea    0x14(%rsp),%r13
xor    %ebp,%ebp
jmp    11d4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1070 <getNth@plt>
mov    %eax,0x10(%rsp)
mov    0xc(%rsp),%esi
lea    0xe3f(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x3,0x14(%rsp)
je     124a <main+0xfa>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
je     1220 <main+0xd0>
cmp    $0x2,%eax
je     1190 <main+0x40>
cmp    $0x3,%eax
je     124a <main+0xfa>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
jmp    11cd <main+0x7d>
nopl   0x0(%rax,%rax,1)
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x10(%rsp),%esi
mov    %rbp,%rdi
call   1050 <insertAtEnd@plt>
mov    %rax,%rbp
jmp    11cd <main+0x7d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.item = type { i32 }
@.str = [38 x i8] c"1. Insert element into a linked list\0A\00"
@.str.1 = [40 x i8] c"2. Find nth element in the linked list\0A\00"
@.str.2 = [14 x i8] c"Enter choice\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [33 x i8] c"Enter the number to be inserted\0A\00"
@.str.5 = [22 x i8] c"Enter the value of n\0A\00"
@.str.6 = [43 x i8] c"The %dth element in the linked list is %d\0A\00"
@.str.7 = [16 x i8] c"Invalid choice\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.item*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store %struct.item* null, %struct.item** %2
br label %6
6: ; preds = %31, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
switch i32 %11, label %28 [
i32 1, label %12
i32 2, label %18
i32 3, label %27
]
12: ; preds = %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%15 = load %struct.item*, %struct.item** %2
%16 = load i32, i32* %4
%17 = call %struct.item* @insertAtEnd(%struct.item* %15, i32 %16)
store %struct.item* %17, %struct.item** %2
br label %30
18: ; preds = %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%21 = load %struct.item*, %struct.item** %2
%22 = load i32, i32* %5
%23 = call i32 @getNth(%struct.item* %21, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %25)
br label %30
27: ; preds = %6
br label %30
28: ; preds = %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %28, %27, %18, %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 3
br i1 %33, label %6, label %34
34: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
%struct.item = type { i32 }
@.str.3 = [3 x i8] c"%d\00"
@.str.6 = [43 x i8] c"The %dth element in the linked list is %d\0A\00"
@str = [37 x i8] c"1. Insert element into a linked list\00"
@str.8 = [39 x i8] c"2. Find nth element in the linked list\00"
@str.9 = [13 x i8] c"Enter choice\00"
@str.10 = [21 x i8] c"Enter the value of n\00"
@str.11 = [32 x i8] c"Enter the number to be inserted\00"
@str.12 = [15 x i8] c"Invalid choice\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*
br label %7
7: ; preds = %28, %0
%8 = phi %struct.item* [ null, %0 ], [ %29, %28 ]
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
switch i32 %13, label %26 [
i32 1, label %14
i32 2, label %19
i32 3, label %32
]
14: ; preds = %7
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = call %struct.item* @insertAtEnd(%struct.item* %8, i32 %17)
br label %28
19: ; preds = %7
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = call i32 @getNth(%struct.item* %8, i32 %22)
store i32 %23, i32* %2
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %23)
br label %28
26: ; preds = %7
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
br label %28
28: ; preds = %14, %19, %26
%29 = phi %struct.item* [ %18, %14 ], [ %8, %19 ], [ %8, %26 ]
%30 = load i32, i32* %1
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %7
32: ; preds = %7, %28
ret i32 0
}