#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 /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
int process_stdin_lines(int (*process_line)(const char *)) {
  int error;
  char *line;
  size_t linecap;
  ssize_t numread;
  error = 0;
  line = NULL;
  while (!error && (numread = getline(&line, &linecap, stdin)) != -1) {
    if (numread > 0) {
      if (line[numread - 1] == '\n') {
        line[numread - 1] = '\0';
      }
      if (line[0] != '\0') {
        error = process_line(line);
      }
    }
  }
  if (ferror(stdin)) {
    perror("stdin");
    error = 1;
  }
  free(line);
  return error;
}


x86 assembly (clang, -O0):
<process_stdin_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x25(%rbp)
jne    118c <process_stdin_lines+0x4c>
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    119c <process_stdin_lines+0x5c>
jmp    11f8 <process_stdin_lines+0xb8>
cmpl   $0x0,-0x24(%rbp)
jle    11f3 <process_stdin_lines+0xb3>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11d1 <process_stdin_lines+0x91>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ee <process_stdin_lines+0xae>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
mov    %eax,-0xc(%rbp)
jmp    11f3 <process_stdin_lines+0xb3>
jmp    115b <process_stdin_lines+0x1b>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1223 <process_stdin_lines+0xe3>
lea    0xde9(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_stdin_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    0x2e89(%rip),%r13
mov    %rsp,%r15
lea    0x8(%rsp),%r12
jmp    1174 <process_stdin_lines+0x34>
nopl   0x0(%rax)
test   %ebx,%ebx
jne    11af <process_stdin_lines+0x6f>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <getline@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     11af <process_stdin_lines+0x6f>
test   %eax,%eax
jle    1170 <process_stdin_lines+0x30>
mov    (%rsp),%rdi
add    $0xffffffff,%eax
cmpb   $0xa,(%rdi,%rax,1)
jne    11a3 <process_stdin_lines+0x63>
movb   $0x0,(%rdi,%rax,1)
mov    (%rsp),%rdi
cmpb   $0x0,(%rdi)
je     1170 <process_stdin_lines+0x30>
call   *%r14
mov    %eax,%ebx
jmp    1170 <process_stdin_lines+0x30>
mov    0x0(%r13),%edi
call   1040 <ferror@plt>
test   %rax,%rax
jne    11d6 <process_stdin_lines+0x96>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe23(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%ebx
jmp    11bd <process_stdin_lines+0x7d>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [6 x i8] c"stdin\00"
define i32 @process_stdin_lines(i32 (i8*)* %0) {
%2 = alloca i32 (i8*)*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 (i8*)* %0, i32 (i8*)** %2
store i32 0, i32* %3
store i8* null, i8** %4
br label %7
7: ; preds = %45, %1
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @stdin
%12 = call i32 @getline(i8** %4, i64* %5, i32 %11)
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %46
16: ; preds = %14
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %45
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %28, %19
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i32 (i8*)*, i32 (i8*)** %2
%42 = load i8*, i8** %4
%43 = call i32 %41(i8* %42)
store i32 %43, i32* %3
br label %44
44: ; preds = %40, %34
br label %45
45: ; preds = %44, %16
br label %7
46: ; preds = %14
%47 = load i32, i32* @stdin
%48 = call i64 @ferror(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %52
52: ; preds = %50, %46
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [6 x i8] c"stdin\00"
define i32 @process_stdin_lines(i32 (i8*)* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
store i8* null, i8** %2
br label %6
6: ; preds = %1, %27
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %2, i64* %3, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %30, label %10
10: ; preds = %6
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %27
12: ; preds = %10
%13 = load i8*, i8** %2
%14 = add nsw i32 %8, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %12
store i8 0, i8* %16
%20 = load i8*, i8** %2
br label %21
21: ; preds = %19, %12
%22 = phi i8* [ %20, %19 ], [ %13, %12 ]
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 %0(i8* %22)
br label %27
27: ; preds = %21, %25, %10
%28 = phi i32 [ %26, %25 ], [ 0, %21 ], [ 0, %10 ]
%29 = icmp eq i32 %28, 0
br i1 %29, label %6, label %30
30: ; preds = %27, %6
%31 = phi i32 [ %28, %27 ], [ 0, %6 ]
%32 = load i32, i32* @stdin
%33 = call i64 @ferror(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = phi i32 [ 1, %35 ], [ %31, %30 ]
%39 = load i8*, i8** %2
%40 = call i32 @free(i8* %39)
ret i32 %38
}