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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ patlist_add(struct patlist **, char *);
void patlist_add_file(struct patlist **dst, const char *fn) {
  FILE *fd;
  char *line;
  size_t linelen = 0;
  size_t len;
  fd = fopen(fn, "r");
  if (NULL == fd)
    return;
  while ((len = getline(&line, &linelen, fd)) != -1) {
    if (len < 1)
      continue;
    if ('\n' == line[len - 1]) {
      if (len == 1)
        continue;
      line[len - 1] = '\0';
    }
    patlist_add(dst, line);
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<patlist_add_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    117d <patlist_add_file+0x3d>
jmp    1209 <patlist_add_file+0xc9>
jmp    1182 <patlist_add_file+0x42>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
mov    %rax,-0x30(%rbp)
cmp    $0xffffffffffffffff,%rax
je     1200 <patlist_add_file+0xc0>
cmpq   $0x1,-0x30(%rbp)
jae    11b1 <patlist_add_file+0x71>
jmp    1182 <patlist_add_file+0x42>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    11ee <patlist_add_file+0xae>
cmpq   $0x1,-0x30(%rbp)
jne    11de <patlist_add_file+0x9e>
jmp    1182 <patlist_add_file+0x42>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <patlist_add@plt>
jmp    1182 <patlist_add_file+0x42>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patlist_add_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
lea    0xe9f(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c4 <patlist_add_file+0x84>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    118f <patlist_add_file+0x4f>
movb   $0x0,-0x1(%rsi,%rax,1)
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <patlist_add@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
test   %rax,%rax
je     118f <patlist_add_file+0x4f>
cmp    $0xffffffffffffffff,%rax
je     11bc <patlist_add_file+0x7c>
mov    0x8(%rsp),%rsi
cmpb   $0xa,-0x1(%rax,%rsi,1)
jne    1187 <patlist_add_file+0x47>
cmp    $0x1,%rax
je     118f <patlist_add_file+0x4f>
jmp    117d <patlist_add_file+0x3d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.patlist = type { i32 }
@.str = [2 x i8] c"r\00"
define void @patlist_add_file(%struct.patlist** %0, i8* %1) {
%3 = alloca %struct.patlist**
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store %struct.patlist** %0, %struct.patlist*** %3
store i8* %1, i8** %4
store i64 0, i64* %7
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* null, %11
br i1 %12, label %13, label %14
13: ; preds = %2
br label %47
14: ; preds = %2
br label %15
15: ; preds = %40, %34, %22, %14
%16 = load i32*, i32** %5
%17 = call i64 @getline(i8** %6, i64* %7, i32* %16)
store i64 %17, i64* %8
%18 = icmp ne i64 %17, -1
br i1 %18, label %19, label %44
19: ; preds = %15
%20 = load i64, i64* %8
%21 = icmp ult i64 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %19
br label %15
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i64, i64* %8
%26 = sub i64 %25, 1
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 10, %29
br i1 %30, label %31, label %40
31: ; preds = %23
%32 = load i64, i64* %8
%33 = icmp eq i64 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %31
br label %15
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = load i64, i64* %8
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35, %23
%41 = load %struct.patlist**, %struct.patlist*** %3
%42 = load i8*, i8** %6
%43 = call i32 @patlist_add(%struct.patlist** %41, i8* %42)
br label %15
44: ; preds = %15
%45 = load i32*, i32** %5
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %13
ret void
}

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