#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, size_t);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getdelim(char **, size_t *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int fput_proc_file(FILE *f, const char *prefix, const char *delim, FILE *o) {
  char *line = 0;
  size_t n = 0;
  for (size_t i = 0;; ++i) {
    errno = 0;
    ssize_t r = getdelim(&line, &n, 0, f);
    if (r == -1)
      break;
    if (i)
      fputs(delim, o);
    if (prefix)
      fprintf(o, "%s[%zu]: ", prefix, i);
    fputs(line, o);
  }
  if (errno) {
    perror("read error");
    free(line);
    return -1;
  }
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<fput_proc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e59(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1070 <getdelim@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    11b3 <fput_proc_file+0x63>
jmp    120c <fput_proc_file+0xbc>
cmpq   $0x0,-0x40(%rbp)
je     11cb <fput_proc_file+0x7b>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
cmpq   $0x0,-0x18(%rbp)
je     11ee <fput_proc_file+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1180 <fput_proc_file+0x30>
mov    0x2dcd(%rip),%rax
cmpq   $0x0,(%rax)
je     123e <fput_proc_file+0xee>
lea    0xde6(%rip),%rdi
call   1060 <perror@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <fput_proc_file+0xfe>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fput_proc_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%r12
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e5c(%rip),%rax
movq   $0x0,(%rax)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
mov    %r12,%rcx
call   1070 <getdelim@plt>
cmp    $0xffffffff,%eax
je     1211 <fput_proc_file+0xc1>
xor    %ebp,%ebp
mov    %rsp,%r14
lea    0x8(%rsp),%r15
jmp    11e3 <fput_proc_file+0x93>
xchg   %ax,%ax
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
add    $0x1,%rbp
mov    0x2e19(%rip),%rax
movq   $0x0,(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
mov    %r12,%rcx
call   1070 <getdelim@plt>
cmp    $0xffffffff,%eax
je     1211 <fput_proc_file+0xc1>
test   %rbp,%rbp
je     11f5 <fput_proc_file+0xa5>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
test   %r13,%r13
je     11b0 <fput_proc_file+0x60>
mov    %rbx,%rdi
lea    0xdfc(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1050 <fprintf@plt>
jmp    11b0 <fput_proc_file+0x60>
mov    0x2dc8(%rip),%rax
cmpq   $0x0,(%rax)
mov    $0x0,%ebx
jne    123d <fput_proc_file+0xed>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc6(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1223 <fput_proc_file+0xd3>

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

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