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

/* Variables and functions */
int /*<<< orphan*/ add_to_keep_list(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
int /*<<< orphan*/ usage();
void add_file_to_keep_list(char *filename) {
  FILE *keepf;
  char symbol[1024];
  int len;
  if ((keepf = fopen(filename, "r")) == NULL) {
    perror(filename);
    usage();
  }
  while (fgets(symbol, 1024, keepf)) {
    len = strlen(symbol);
    if (len && symbol[len - 1] == '\n')
      symbol[len - 1] = '\0';
    add_to_keep_list(symbol);
  }
  fclose(keepf);
}


x86 assembly (clang, -O0):
<add_file_to_keep_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ad <add_file_to_keep_list+0x3d>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    11b2 <add_file_to_keep_list+0x42>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1230 <add_file_to_keep_list+0xc0>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
je     121f <add_file_to_keep_list+0xaf>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    121f <add_file_to_keep_list+0xaf>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1090 <add_to_keep_list@plt>
jmp    11b2 <add_file_to_keep_list+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_file_to_keep_list>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ec <add_file_to_keep_list+0x7c>
mov    %rsp,%rbx
jmp    11a8 <add_file_to_keep_list+0x38>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <add_to_keep_list@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d9 <add_file_to_keep_list+0x69>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11a0 <add_file_to_keep_list+0x30>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11a0 <add_file_to_keep_list+0x30>
movb   $0x0,-0x1(%rsp,%rax,1)
jmp    11a0 <add_file_to_keep_list+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1080 <perror@plt>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    1191 <add_file_to_keep_list+0x21>

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

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