#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 *add_to_list(struct node *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
struct node *read_numbers(void) {
  struct node *first = NULL;
  int n;
  printf("Enter a series of integers (0 to terminate): ");
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      return first;
    first = add_to_list(first, n);
  }
}


x86 assembly (clang, -O0):
<read_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1170 <read_numbers+0x40>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <add_to_list@plt>
mov    %rax,-0x8(%rbp)
jmp    114c <read_numbers+0x1c>

x86 assembly (clang, -O2):
<read_numbers>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
xor    %ebx,%ebx
test   %esi,%esi
je     118e <read_numbers+0x5e>
lea    0xec7(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <add_to_list@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jne    1170 <read_numbers+0x40>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [46 x i8] c"Enter a series of integers (0 to terminate): \00"
@.str.1 = [3 x i8] c"%d\00"
define %struct.node* @read_numbers() {
%1 = alloca %struct.node*
%2 = alloca i32
store %struct.node* null, %struct.node** %1
%3 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %10, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load %struct.node*, %struct.node** %1
ret %struct.node* %9
10: ; preds = %4
%11 = load %struct.node*, %struct.node** %1
%12 = load i32, i32* %2
%13 = call %struct.node* @add_to_list(%struct.node* %11, i32 %12)
store %struct.node* %13, %struct.node** %1
br label %4
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [46 x i8] c"Enter a series of integers (0 to terminate): \00"
@.str.1 = [3 x i8] c"%d\00"
define %struct.node* @read_numbers() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %9, %0
%8 = phi %struct.node* [ null, %0 ], [ %12, %9 ]
ret %struct.node* %8
9: ; preds = %0, %9
%10 = phi i32 [ %14, %9 ], [ %5, %0 ]
%11 = phi %struct.node* [ %12, %9 ], [ null, %0 ]
%12 = call %struct.node* @add_to_list(%struct.node* %11, i32 %10)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %7, label %9
}