#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 */
int /*<<< orphan*/ append(struct node **, char);
int calc(struct node *, int /*<<< orphan*/, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ length(struct node *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct node *head = NULL;
  char c;
  while ((c = getchar()) != '\n') {
    append(&head, c);
  }
  printf("%d\n", calc(head, 0, length(head)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     118f <main+0x3f>
lea    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <append@plt>
jmp    1167 <main+0x17>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <length@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <calc@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     118b <main+0x3b>
lea    0x8(%rsp),%rbx
movsbl %al,%esi
mov    %rbx,%rdi
call   1030 <append@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1170 <main+0x20>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <length@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <calc@plt>
lea    0xe5a(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.node*
%3 = alloca i8
store i32 0, i32* %1
store %struct.node* null, %struct.node** %2
br label %4
4: ; preds = %8, %0
%5 = call signext i8 (...) @getchar()
store i8 %5, i8* %3
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 10
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i8, i8* %3
%10 = call i32 @append(%struct.node** %2, i8 signext %9)
br label %4
11: ; preds = %4
%12 = load %struct.node*, %struct.node** %2
%13 = load %struct.node*, %struct.node** %2
%14 = call i32 @length(%struct.node* %13)
%15 = call i32 @calc(%struct.node* %12, i32 0, i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca %struct.node*
%2 = bitcast %struct.node** %1 to i8*
store %struct.node* null, %struct.node** %1
%3 = call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 10
br i1 %4, label %12, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %8, %5 ], [ %3, %0 ]
%7 = call i32 @append(%struct.node** %1, i8 signext %6)
%8 = call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = load %struct.node*, %struct.node** %1
br label %12
12: ; preds = %10, %0
%13 = phi %struct.node* [ %11, %10 ], [ null, %0 ]
%14 = call i32 @length(%struct.node* %13)
%15 = call i32 @calc(%struct.node* %13, i32 0, i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 0
}