#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 int ssize_t;

/* Variables and functions */
scalar_t__ ferror(int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, size_t, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char *buf = NULL;
  size_t size = 0;
  ssize_t len;
  while ((len = getline(&buf, &size, stdin)) != -1) {
    printf("bufsize %Zu; read %Zd: ", size, len);
    if (fwrite(buf, len, 1, stdout) != 1) {
      perror("fwrite");
      return 1;
    }
  }
  if (ferror(stdin)) {
    perror("getline");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11eb <main+0x9b>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     11e6 <main+0x96>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xd2>
jmp    1176 <main+0x26>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     121b <main+0xcb>
lea    0xe15(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xd2>
movl   $0x0,-0x4(%rbp)
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
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e71(%rip),%r13
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%rbx
lea    0xe78(%rip),%r12
mov    0x2e49(%rip),%r14
nop
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11d7 <main+0x87>
mov    %eax,%ebp
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
mov    (%r14),%ecx
mov    %ebp,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     1190 <main+0x40>
lea    0xe43(%rip),%rdi
jmp    1200 <main+0xb0>
mov    0x0(%r13),%edi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11f9 <main+0xa9>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    11ea <main+0x9a>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [24 x i8] c"bufsize %Zu; read %Zd: \00"
@stdout = global i32 0
@.str.1 = [7 x i8] c"fwrite\00"
@.str.2 = [8 x i8] c"getline\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %6, i64* %7, i32 %10)
store i32 %11, i32* %8
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i64, i64* %7
%15 = load i32, i32* %8
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %15)
%17 = load i8*, i8** %6
%18 = load i32, i32* %8
%19 = load i32, i32* @stdout
%20 = call i32 @fwrite(i8* %17, i32 %18, i32 1, i32 %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %32
24: ; preds = %13
br label %9
25: ; preds = %9
%26 = load i32, i32* @stdin
%27 = call i64 @ferror(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %32
31: ; preds = %25
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29, %22
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [24 x i8] c"bufsize %Zu; read %Zd: \00"
@stdout = global i32 0
@.str.1 = [7 x i8] c"fwrite\00"
@.str.2 = [8 x i8] c"getline\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %11, %2
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %3, i64* %4, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i64, i64* %4
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %12, i32 %9)
%14 = load i8*, i8** %3
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %14, i32 %9, i32 1, i32 %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %7, label %22
18: ; preds = %7
%19 = load i32, i32* @stdin
%20 = call i64 @ferror(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %11, %18
%23 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %11 ]
%24 = call i32 @perror(i8* %23)
br label %25
25: ; preds = %22, %18
%26 = phi i32 [ 0, %18 ], [ 1, %22 ]
ret i32 %26
}