#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;
int main(void) {
  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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1204 <main+0xc4>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1060 <scanf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11c7 <main+0x87>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11d3 <main+0x93>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1f(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <scanf@plt>
jmp    116d <main+0x2d>
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     125f <main+0x11f>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1226 <main+0xe6>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%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>
xor    %eax,%eax
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 i32 @main() {
%1 = alloca i32
%2 = alloca %struct.node*
%3 = alloca %struct.node*
%4 = alloca %struct.node*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store %struct.node* null, %struct.node** %4
store i32 0, i32* %5
store i32 1, i32* %6
store %struct.node* null, %struct.node** %3
br label %7
7: ; preds = %26, %0
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = call i64 @malloc(i32 16)
%12 = inttoptr i64 %11 to %struct.node*
store %struct.node* %12, %struct.node** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%14 = load %struct.node*, %struct.node** %2
%15 = getelementptr inbounds %struct.node, %struct.node* %14, i32 0, i32 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = load %struct.node*, %struct.node** %3
%18 = icmp ne %struct.node* %17, null
br i1 %18, label %19, label %24
19: ; preds = %10
%20 = load %struct.node*, %struct.node** %2
%21 = load %struct.node*, %struct.node** %4
%22 = getelementptr inbounds %struct.node, %struct.node* %21, i32 0, i32 1
store %struct.node* %20, %struct.node** %22
%23 = load %struct.node*, %struct.node** %2
store %struct.node* %23, %struct.node** %4
br label %26
24: ; preds = %10
%25 = load %struct.node*, %struct.node** %2
store %struct.node* %25, %struct.node** %4
store %struct.node* %25, %struct.node** %3
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* @stdin
%28 = call i32 @fflush(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
br label %7
31: ; preds = %7
%32 = load %struct.node*, %struct.node** %4
%33 = getelementptr inbounds %struct.node, %struct.node* %32, i32 0, i32 1
store %struct.node* null, %struct.node** %33
%34 = load %struct.node*, %struct.node** %3
store %struct.node* %34, %struct.node** %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %39, %31
%37 = load %struct.node*, %struct.node** %4
%38 = icmp ne %struct.node* %37, null
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load %struct.node*, %struct.node** %4
%41 = getelementptr inbounds %struct.node, %struct.node* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
%46 = load %struct.node*, %struct.node** %4
%47 = getelementptr inbounds %struct.node, %struct.node* %46, i32 0, i32 1
%48 = load %struct.node*, %struct.node** %47
store %struct.node* %48, %struct.node** %4
br label %36
49: ; preds = %36
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %1
ret i32 %53
}

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 i32 @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 i32 0
}