#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 */
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int interactive(void) {
  char buf[4096];
  ssize_t ret, total;
  total = 0;
  do {
    ret = read(STDIN_FILENO, buf, sizeof(buf));
    if (ret < 0) {
      perror("unable to read from input");
      return 1;
    }
    total += ret;
  } while (ret);
  printf("%ld\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<interactive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movq   $0x0,-0x1020(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jge    118d <interactive+0x5d>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ca <interactive+0x9a>
mov    -0x1018(%rbp),%rax
add    -0x1020(%rbp),%rax
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1146 <interactive+0x16>
mov    -0x1020(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interactive>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
xor    %ebx,%ebx
mov    0x2e9b(%rip),%r15
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %rax,%rax
js     118b <interactive+0x5b>
add    %rax,%rbx
test   %rax,%rax
jne    1150 <interactive+0x20>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    117e <interactive+0x4e>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [26 x i8] c"unable to read from input\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @interactive() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i64
%4 = alloca i64
store i64 0, i64* %4
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* @STDIN_FILENO
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = call i64 @read(i32 %6, i8* %7, i32 4096)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %23
13: ; preds = %5
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = add nsw i64 %15, %14
store i64 %16, i64* %4
br label %17
17: ; preds = %13
%18 = load i64, i64* %3
%19 = icmp ne i64 %18, 0
br i1 %19, label %5, label %20
20: ; preds = %17
%21 = load i64, i64* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %21)
store i32 0, i32* %1
br label %23
23: ; preds = %20, %11
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [26 x i8] c"unable to read from input\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @interactive() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %10, %0
%4 = phi i64 [ 0, %0 ], [ %11, %10 ]
%5 = load i32, i32* @STDIN_FILENO
%6 = call i64 @read(i32 %5, i8* %2, i32 4096)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %3
%11 = add nsw i64 %6, %4
%12 = icmp eq i64 %6, 0
br i1 %12, label %13, label %3
13: ; preds = %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %15
15: ; preds = %13, %8
%16 = phi i32 [ 1, %8 ], [ 0, %13 ]
ret i32 %16
}