#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *make_str_clean(char *);
int /*<<< orphan*/ printf(char *, char const *);
char *strdup(char *);
size_t read_config_lines(const char *config_file_name,
                         char *valid_config_lines[]) {
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  size_t valid_line_num;
  valid_line_num = 0;
  fp = fopen(config_file_name, "r");
  if (fp == NULL) {
    printf("ERROR: cannot read config file: %s\n", config_file_name);
    exit(EXIT_FAILURE);
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    line = make_str_clean(line);
    if (*line != '#') {
      valid_config_lines[valid_line_num++] = strdup(line);
    }
  }
  fclose(fp);
  if (line)
    free(line);
  return valid_line_num;
}


x86 assembly (clang, -O0):
<read_config_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e5 <read_config_lines+0x65>
mov    -0x8(%rbp),%rsi
lea    0xe30(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11ea <read_config_lines+0x6a>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     124c <read_config_lines+0xcc>
mov    -0x20(%rbp),%rdi
call   1040 <make_str_clean@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1247 <read_config_lines+0xc7>
mov    -0x20(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rdx,(%rax,%rcx,8)
jmp    11ea <read_config_lines+0x6a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1269 <read_config_lines+0xe9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123e <read_config_lines+0xbe>
mov    %rax,%r15
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     1217 <read_config_lines+0x97>
mov    %rsp,%r12
lea    0x8(%rsp),%r13
jmp    11f3 <read_config_lines+0x73>
nopl   (%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1217 <read_config_lines+0x97>
mov    (%rsp),%rdi
call   1040 <make_str_clean@plt>
mov    %rax,(%rsp)
cmpb   $0x23,(%rax)
je     11e0 <read_config_lines+0x60>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
jmp    11e0 <read_config_lines+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     122d <read_config_lines+0xad>
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdbd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"ERROR: cannot read config file: %s\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @read_config_lines(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i8* null, i8** %6
store i64 0, i64* %7
store i64 0, i64* %9
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
br label %20
20: ; preds = %38, %19
%21 = load i32*, i32** %5
%22 = call i32 @getline(i8** %6, i64* %7, i32* %21)
store i32 %22, i32* %8
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = call i8* @make_str_clean(i8* %25)
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 35
br i1 %30, label %31, label %38
31: ; preds = %24
%32 = load i8*, i8** %6
%33 = call i8* @strdup(i8* %32)
%34 = load i8**, i8*** %4
%35 = load i64, i64* %9
%36 = add i64 %35, 1
store i64 %36, i64* %9
%37 = getelementptr inbounds i8*, i8** %34, i64 %35
store i8* %33, i8** %37
br label %38
38: ; preds = %31, %24
br label %20
39: ; preds = %20
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %44, %39
%48 = load i64, i64* %9
ret i64 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"ERROR: cannot read config file: %s\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @read_config_lines(i8* %0, i8** nocapture writeonly %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 %12, label %9
9: ; preds = %2
%10 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %30, label %16
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9, %26
%17 = phi i64 [ %27, %26 ], [ 0, %9 ]
%18 = load i8*, i8** %3
%19 = call i8* @make_str_clean(i8* %18)
store i8* %19, i8** %3
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 35
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = call i8* @strdup(i8* %19)
%24 = add i64 %17, 1
%25 = getelementptr inbounds i8*, i8** %1, i64 %17
store i8* %23, i8** %25
br label %26
26: ; preds = %22, %16
%27 = phi i64 [ %24, %22 ], [ %17, %16 ]
%28 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %16
30: ; preds = %26, %9
%31 = phi i64 [ 0, %9 ], [ %27, %26 ]
%32 = call i32 @fclose(i32* %7)
%33 = load i8*, i8** %3
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 @free(i8* %33)
br label %37
37: ; preds = %35, %30
ret i64 %31
}