#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strdup(int /*<<< orphan*/ *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *get_line(char *fn, char *match) {
  ssize_t read;
  char *line = NULL;
  char *ret = NULL;
  size_t len = 0;
  FILE *fp = fopen(fn, "r");
  if (fp == NULL) {
    fprintf(stderr, "E: Couldn't open file '%s'\n", fn);
    return NULL;
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    if (strstr(line, match) != NULL) {
      ret = strdup(strstr(line, match) + strlen(match));
      break;
    }
  }
  if (!ret)
    fprintf(stderr, "E: %s not found in %s\n", match, fn);
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11df <get_line+0x6f>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    128d <get_line+0x11d>
jmp    11e4 <get_line+0x74>
mov    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1252 <get_line+0xe2>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     124d <get_line+0xdd>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1252 <get_line+0xe2>
jmp    11e4 <get_line+0x74>
cmpq   $0x0,-0x30(%rbp)
jne    127c <get_line+0x10c>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1234 <get_line+0xc4>
mov    %rax,%rbx
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     120a <get_line+0x9a>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c0 <get_line+0x50>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    0x0(,%rax,4),%rdi
add    %rbp,%rdi
call   1080 <strdup@plt>
mov    %rax,%r12
test   %rax,%rax
jne    122a <get_line+0xba>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
xor    %r12d,%r12d
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1251 <get_line+0xe1>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"E: Couldn't open file '%s'\0A\00"
@.str.2 = [23 x i8] c"E: %s not found in %s\0A\00"
define i8* @get_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %7
store i8* null, i8** %8
store i64 0, i64* %9
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i8* null, i8** %3
br label %51
19: ; preds = %2
br label %20
20: ; preds = %38, %19
%21 = load i32*, i32** %10
%22 = call i32 @getline(i8** %7, i64* %9, i32* %21)
store i32 %22, i32* %6
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = load i8*, i8** %5
%27 = call i32* @strstr(i8* %25, i8* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i8*, i8** %7
%31 = load i8*, i8** %5
%32 = call i32* @strstr(i8* %30, i8* %31)
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %32, i64 %35
%37 = call i8* @strdup(i32* %36)
store i8* %37, i8** %8
br label %39
38: ; preds = %24
br label %20
39: ; preds = %29, %20
%40 = load i8*, i8** %8
%41 = icmp ne i8* %40, null
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %5
%45 = load i8*, i8** %4
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %45)
br label %47
47: ; preds = %42, %39
%48 = load i32*, i32** %10
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %8
store i8* %50, i8** %3
br label %51
51: ; preds = %47, %15
%52 = load i8*, i8** %3
ret i8* %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"E: Couldn't open file '%s'\0A\00"
@.str.2 = [23 x i8] c"E: %s not found in %s\0A\00"
define i8* @get_line(i8* %0, i8* %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
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
12: ; preds = %2, %15
%13 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i32* @strstr(i8* dereferenceable(1) %16, i8* dereferenceable(1) %1)
%18 = icmp eq i32* %17, null
br i1 %18, label %12, label %19
19: ; preds = %15
%20 = call i32 @strlen(i8* %1)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = call i8* @strdup(i32* %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %12, %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0)
br label %28
28: ; preds = %25, %19
%29 = phi i8* [ null, %25 ], [ %23, %19 ]
%30 = call i32 @fclose(i32* %7)
br label %31
31: ; preds = %28, %9
%32 = phi i8* [ null, %9 ], [ %29, %28 ]
ret i8* %32
}