#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*/ fflush(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
void main() {
  struct node {
    int num;
    struct node *ptr;
  };
  typedef struct node NODE;
  NODE *head, *first, *temp = 0;
  int count = 0;
  int choice = 1;
  first = 0;
  while (choice) {
    head = (NODE *)malloc(sizeof(NODE));
    printf("Enter the data item\n");
    scanf("%d", &head->num);
    if (first != 0) {
      temp->ptr = head;
      temp = head;
    } else {
      first = temp = head;
    }
    fflush(stdin);
    printf("Do you want to continue(Type 0 or 1)?\n");
    scanf("%d", &choice);
  }
  temp->ptr = 0;
  temp = first;
  printf("\n status of the linked list is\n");
  while (temp != 0) {
    printf("%d=>", temp->num);
    count++;
    temp = temp->ptr;
  }
  printf("NULL\n");
  printf("No. of nodes in the list = %d\n", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11fd <main+0xbd>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1060 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c0 <main+0x80>
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11cc <main+0x8c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe26(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <scanf@plt>
jmp    1166 <main+0x26>
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1258 <main+0x118>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121f <main+0xdf>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
xor    %ebx,%ebx
lea    0xe94(%rip),%r13
lea    0xeec(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
jmp    11af <main+0x5f>
nopl   0x0(%rax)
mov    %r14,0x8(%rbx)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
mov    %r14,%rbx
je     11dd <main+0x8d>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
test   %rbp,%rbp
jne    1180 <main+0x30>
mov    %r14,%rbp
jmp    1184 <main+0x34>
movq   $0x0,0x8(%r14)
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
test   %rbp,%rbp
je     121b <main+0xcb>
lea    0xe06(%rip),%r14
xor    %ebx,%ebx
nop
mov    0x0(%rbp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
mov    0x8(%rbp),%rbp
test   %rbp,%rbp
jne    1200 <main+0xb0>
jmp    121d <main+0xcd>
xor    %ebx,%ebx
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32, %struct.node* }
@.str = [21 x i8] c"Enter the data item\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [39 x i8] c"Do you want to continue(Type 0 or 1)?\0A\00"
@.str.3 = [32 x i8] c"\0A status of the linked list is\0A\00"
@.str.4 = [5 x i8] c"%d=>\00"
@.str.5 = [6 x i8] c"NULL\0A\00"
@.str.6 = [31 x i8] c"No. of nodes in the list = %d\0A\00"
define void @main() {
%1 = alloca %struct.node*
%2 = alloca %struct.node*
%3 = alloca %struct.node*
%4 = alloca i32
%5 = alloca i32
store %struct.node* null, %struct.node** %3
store i32 0, i32* %4
store i32 1, i32* %5
store %struct.node* null, %struct.node** %2
br label %6
6: ; preds = %25, %0
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = call i64 @malloc(i32 16)
%11 = inttoptr i64 %10 to %struct.node*
store %struct.node* %11, %struct.node** %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.node*, %struct.node** %1
%14 = getelementptr inbounds %struct.node, %struct.node* %13, i32 0, i32 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = load %struct.node*, %struct.node** %2
%17 = icmp ne %struct.node* %16, null
br i1 %17, label %18, label %23
18: ; preds = %9
%19 = load %struct.node*, %struct.node** %1
%20 = load %struct.node*, %struct.node** %3
%21 = getelementptr inbounds %struct.node, %struct.node* %20, i32 0, i32 1
store %struct.node* %19, %struct.node** %21
%22 = load %struct.node*, %struct.node** %1
store %struct.node* %22, %struct.node** %3
br label %25
23: ; preds = %9
%24 = load %struct.node*, %struct.node** %1
store %struct.node* %24, %struct.node** %3
store %struct.node* %24, %struct.node** %2
br label %25
25: ; preds = %23, %18
%26 = load i32, i32* @stdin
%27 = call i32 @fflush(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %6
30: ; preds = %6
%31 = load %struct.node*, %struct.node** %3
%32 = getelementptr inbounds %struct.node, %struct.node* %31, i32 0, i32 1
store %struct.node* null, %struct.node** %32
%33 = load %struct.node*, %struct.node** %2
store %struct.node* %33, %struct.node** %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %38, %30
%36 = load %struct.node*, %struct.node** %3
%37 = icmp ne %struct.node* %36, null
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load %struct.node*, %struct.node** %3
%40 = getelementptr inbounds %struct.node, %struct.node* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = load %struct.node*, %struct.node** %3
%46 = getelementptr inbounds %struct.node, %struct.node* %45, i32 0, i32 1
%47 = load %struct.node*, %struct.node** %46
store %struct.node* %47, %struct.node** %3
br label %35
48: ; preds = %35
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%50 = load i32, i32* %4
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %50)
ret void
}

LLVM IR (-O2):
%struct.node = type { i32, %struct.node* }
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.4 = [5 x i8] c"%d=>\00"
@.str.6 = [31 x i8] c"No. of nodes in the list = %d\0A\00"
@str = [31 x i8] c"\0A status of the linked list is\00"
@str.7 = [5 x i8] c"NULL\00"
@str.8 = [20 x i8] c"Enter the data item\00"
@str.9 = [38 x i8] c"Do you want to continue(Type 0 or 1)?\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
br label %3
3: ; preds = %0, %14
%4 = phi %struct.node* [ null, %0 ], [ %7, %14 ]
%5 = phi %struct.node* [ null, %0 ], [ %15, %14 ]
%6 = call i64 @malloc(i32 16)
%7 = inttoptr i64 %6 to %struct.node*
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%9 = getelementptr inbounds %struct.node, %struct.node* %7, i64 0, i32 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%11 = icmp eq %struct.node* %5, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = getelementptr inbounds %struct.node, %struct.node* %4, i64 0, i32 1
store %struct.node* %7, %struct.node** %13
br label %14
14: ; preds = %3, %12
%15 = phi %struct.node* [ %5, %12 ], [ %7, %3 ]
%16 = load i32, i32* @stdin
%17 = call i32 @fflush(i32 %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.9, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %3
22: ; preds = %14
%23 = inttoptr i64 %6 to %struct.node*
%24 = getelementptr inbounds %struct.node, %struct.node* %23, i64 0, i32 1
store %struct.node* null, %struct.node** %24
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%26 = icmp eq %struct.node* %15, null
br i1 %26, label %37, label %27
27: ; preds = %22, %27
%28 = phi i32 [ %33, %27 ], [ 0, %22 ]
%29 = phi %struct.node* [ %35, %27 ], [ %15, %22 ]
%30 = getelementptr inbounds %struct.node, %struct.node* %29, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i32 %28, 1
%34 = getelementptr inbounds %struct.node, %struct.node* %29, i64 0, i32 1
%35 = load %struct.node*, %struct.node** %34
%36 = icmp eq %struct.node* %35, null
br i1 %36, label %37, label %27
37: ; preds = %27, %22
%38 = phi i32 [ 0, %22 ], [ %33, %27 ]
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %38)
ret void
}