#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 */
struct process_info {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
void call_on_line(const char *input_file,
                  void (*action)(char *, struct process_info *),
                  struct process_info *data) {
  char *line;
  FILE *file_stream = NULL;
  ssize_t read;
  size_t len = 0;
  int open_failed = 0;
  file_stream = fopen(input_file, "r");
  if (file_stream == NULL) {
    printf("Could not open file %s\n", input_file);
    open_failed = 1;
  }
  if (open_failed == 0) {
    while ((read = getline(&line, &len, file_stream)) != -1) {
      action(line, data);
    }
    if (line) {
      free(line);
    }
    fclose(file_stream);
  }
  return;
}


x86 assembly (clang, -O0):
<call_on_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b1 <call_on_line+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    120d <call_on_line+0xbd>
jmp    11c0 <call_on_line+0x70>
mov    -0x28(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     11f0 <call_on_line+0xa0>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
jmp    11c0 <call_on_line+0x70>
cmpq   $0x0,-0x20(%rbp)
je     1204 <call_on_line+0xb4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_on_line>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e1 <call_on_line+0x91>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     11bd <call_on_line+0x6d>
mov    %rsp,%r12
lea    0x8(%rsp),%r13
mov    (%rsp),%rdi
mov    %r14,%rsi
call   *%r15
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
jne    11a0 <call_on_line+0x50>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11cb <call_on_line+0x7b>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe1a(%rip),%rdi
mov    %r12,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.process_info = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
define void @call_on_line(i8* %0, void (i8*, %struct.process_info*)* %1, %struct.process_info* %2) {
%4 = alloca i8*
%5 = alloca void (i8*, %struct.process_info*)*
%6 = alloca %struct.process_info*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store void (i8*, %struct.process_info*)* %1, void (i8*, %struct.process_info*)** %5
store %struct.process_info* %2, %struct.process_info** %6
store i32* null, i32** %8
store i64 0, i64* %10
store i32 0, i32* %11
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %11
br label %19
19: ; preds = %16, %3
%20 = load i32, i32* %11
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %19
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %8
%25 = call i32 @getline(i8** %7, i64* %10, i32* %24)
store i32 %25, i32* %9
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load void (i8*, %struct.process_info*)*, void (i8*, %struct.process_info*)** %5
%29 = load i8*, i8** %7
%30 = load %struct.process_info*, %struct.process_info** %6
br label %23
31: ; preds = %23
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %19
ret void
}

LLVM IR (-O2):
%struct.process_info = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
define void @call_on_line(i8* %0, void (i8*, %struct.process_info*)* nocapture %1, %struct.process_info* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = call i32 @getline(i8** %4, i64* %5, i32* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %19, label %15
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
15: ; preds = %10, %15
%16 = load i8*, i8** %4
%17 = call i32 @getline(i8** %4, i64* %5, i32* %8)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %15
19: ; preds = %15, %10
%20 = load i8*, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @free(i8* %20)
br label %24
24: ; preds = %22, %19
%25 = call i32 @fclose(i32* %8)
br label %26
26: ; preds = %13, %24
ret void
}