#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 */

/* Variables and functions */
int /*<<< orphan*/ buffer_for_each_line(char *, int,
                                        int (*)(void *, char const *), void *);
char *mmap_file(char const *, int *);
int /*<<< orphan*/ munmap(char *, int);
int file_for_each_line(const char *filename,
                       int (*cb)(void *data, const char *line), void *data) {
  char *buf;
  int size;
  buf = mmap_file(filename, &size);
  if (size == -1)
    return -1;
  if (buf) {
    buffer_for_each_line(buf, size, cb, data);
    munmap(buf, size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<file_for_each_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <mmap_file@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    116b <file_for_each_line+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <file_for_each_line+0x6d>
cmpq   $0x0,-0x28(%rbp)
je     1196 <file_for_each_line+0x66>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <buffer_for_each_line@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_for_each_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
lea    0x4(%rsp),%rsi
call   1050 <mmap_file@plt>
mov    0x4(%rsp),%esi
cmp    $0xffffffff,%esi
je     1176 <file_for_each_line+0x46>
mov    %rax,%rbx
xor    %ebp,%ebp
test   %rax,%rax
je     117b <file_for_each_line+0x4b>
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <buffer_for_each_line@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <munmap@plt>
jmp    117b <file_for_each_line+0x4b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @file_for_each_line(i8* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i8* @mmap_file(i8* %10, i32* %9)
store i8* %11, i8** %8
%12 = load i32, i32* %9
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %28
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%22 = load i8*, i8** %7
%23 = call i32 @buffer_for_each_line(i8* %19, i32 %20, i32 (i8*, i8*)* %21, i8* %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = call i32 @munmap(i8* %24, i32 %25)
br label %27
27: ; preds = %18, %15
store i32 0, i32* %4
br label %28
28: ; preds = %27, %14
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @file_for_each_line(i8* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i8* @mmap_file(i8* %0, i32* %4)
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = icmp eq i8* %6, null
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = call i32 @buffer_for_each_line(i8* %6, i32 %7, i32 (i8*, i8*)* %1, i8* %2)
%13 = load i32, i32* %4
%14 = call i32 @munmap(i8* %6, i32 %13)
br label %15
15: ; preds = %9, %11, %3
%16 = phi i32 [ -1, %3 ], [ 0, %11 ], [ 0, %9 ]
ret i32 %16
}