#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_value(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int strlen(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ strtrim(char *);
char *xstrdup(int /*<<< orphan*/);
void get_flags(const char *filename, char **cflags, char **cxxflags) {
  FILE *file;
  char *line, *token;
  size_t n;
  int nread;
  *cflags = NULL;
  *cxxflags = NULL;
  if (filename != NULL)
    file = fopen(filename, "r");
  else
    file = fopen("/etc/pkgmk.conf", "r");
  if (file == NULL)
    return;
  line = 0;
  while ((nread = getline(&line, &n, file)) >= 0) {
    *(line + strlen(line) - 1) = 0;
    strtrim(line);
    if (*line == '#')
      continue;
    if ((token = strstr(line, "CFLAGS")) != NULL) {
      free(*cflags);
      *cflags = xstrdup(get_value(token));
    } else if ((token = strstr(line, "CXXFLAGS")) != NULL) {
      free(*cxxflags);
      *cxxflags = xstrdup(get_value(line));
    } else
      continue;
  }
  free(line);
  fclose(file);
}


x86 assembly (clang, -O0):
<get_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11de <get_flags+0x4e>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11f5 <get_flags+0x65>
lea    0xe1d(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <get_flags+0x75>
jmp    131a <get_flags+0x18a>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jl     1308 <get_flags+0x178>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1080 <strtrim@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1267 <get_flags+0xd7>
jmp    120d <get_flags+0x7d>
mov    -0x28(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12b0 <get_flags+0x120>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1070 <get_value@plt>
mov    %eax,%edi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1303 <get_flags+0x173>
mov    -0x28(%rbp),%rdi
lea    0xd5e(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12f9 <get_flags+0x169>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <get_value@plt>
mov    %eax,%edi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12fe <get_flags+0x16e>
jmp    120d <get_flags+0x7d>
jmp    1303 <get_flags+0x173>
jmp    120d <get_flags+0x7d>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_flags>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
movq   $0x0,(%rsi)
mov    %rdx,0x8(%rsp)
movq   $0x0,(%rdx)
test   %rdi,%rdi
jne    11c0 <get_flags+0x30>
lea    0xe42(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12be <get_flags+0x12e>
movq   $0x0,(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
test   %eax,%eax
js     12ad <get_flags+0x11d>
mov    %rsp,%r12
lea    0x10(%rsp),%r13
jmp    1243 <get_flags+0xb3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r14
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1070 <get_value@plt>
mov    %r15,%rbp
mov    %eax,%edi
call   1060 <xstrdup@plt>
mov    %rax,0x0(%rbp)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
test   %eax,%eax
js     12ad <get_flags+0x11d>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rbp,%rax,1)
mov    (%rsp),%rdi
call   1080 <strtrim@plt>
mov    (%rsp),%rbp
cmpb   $0x23,0x0(%rbp)
je     1231 <get_flags+0xa1>
mov    %rbp,%rdi
lea    0xd9f(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
jne    1210 <get_flags+0x80>
mov    %rbp,%rdi
lea    0xd92(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1231 <get_flags+0xa1>
mov    0x8(%rsp),%rbp
mov    0x0(%rbp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1070 <get_value@plt>
jmp    1226 <get_flags+0x96>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
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"
@.str.1 = [16 x i8] c"/etc/pkgmk.conf\00"
@.str.2 = [7 x i8] c"CFLAGS\00"
@.str.3 = [9 x i8] c"CXXFLAGS\00"
define void @get_flags(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%12 = load i8**, i8*** %5
store i8* null, i8** %12
%13 = load i8**, i8*** %6
store i8* null, i8** %13
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
br label %21
19: ; preds = %3
%20 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %7
br label %21
21: ; preds = %19, %16
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
br label %76
25: ; preds = %21
store i8* null, i8** %8
br label %26
26: ; preds = %70, %68, %43, %25
%27 = load i32*, i32** %7
%28 = call i32 @getline(i8** %8, i64* %10, i32* %27)
store i32 %28, i32* %11
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %71
30: ; preds = %26
%31 = load i8*, i8** %8
%32 = load i8*, i8** %8
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -1
store i8 0, i8* %36
%37 = load i8*, i8** %8
%38 = call i32 @strtrim(i8* %37)
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 35
br i1 %42, label %43, label %44
43: ; preds = %30
br label %26
44: ; preds = %30
%45 = load i8*, i8** %8
%46 = call i8* @strstr(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %46, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i8**, i8*** %5
%50 = load i8*, i8** %49
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %9
%53 = call i32 @get_value(i8* %52)
%54 = call i8* @xstrdup(i32 %53)
%55 = load i8**, i8*** %5
store i8* %54, i8** %55
br label %70
56: ; preds = %44
%57 = load i8*, i8** %8
%58 = call i8* @strstr(i8* %57, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %58, i8** %9
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %68
60: ; preds = %56
%61 = load i8**, i8*** %6
%62 = load i8*, i8** %61
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %8
%65 = call i32 @get_value(i8* %64)
%66 = call i8* @xstrdup(i32 %65)
%67 = load i8**, i8*** %6
store i8* %66, i8** %67
br label %69
68: ; preds = %56
br label %26
69: ; preds = %60
br label %70
70: ; preds = %69, %48
br label %26
71: ; preds = %26
%72 = load i8*, i8** %8
%73 = call i32 @free(i8* %72)
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
br label %76
76: ; preds = %71, %24
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"/etc/pkgmk.conf\00"
@.str.2 = [7 x i8] c"CFLAGS\00"
@.str.3 = [9 x i8] c"CXXFLAGS\00"
define void @get_flags(i8* %0, i8** nocapture %1, i8** nocapture %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
%7 = bitcast i64* %5 to i8*
store i8* null, i8** %1
store i8* null, i8** %2
%8 = icmp eq i8* %0, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %3
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = phi i32* [ %10, %9 ], [ %12, %11 ]
%15 = icmp eq i32* %14, null
br i1 %15, label %56, label %16
16: ; preds = %13
store i8* null, i8** %4
%17 = call i32 @getline(i8** %4, i64* %5, i32* %14)
%18 = icmp sgt i32 %17, -1
br i1 %18, label %19, label %52
19: ; preds = %16, %49
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 -1
%24 = getelementptr inbounds i8, i8* %23, i64 %22
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = call i32 @strtrim(i8* %25)
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 35
br i1 %29, label %49, label %30
30: ; preds = %19
%31 = call i8* @strstr(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i8*, i8** %1
%35 = call i32 @free(i8* %34)
%36 = call i32 @get_value(i8* %31)
br label %45
37: ; preds = %30
%38 = call i8* @strstr(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %49, label %40
40: ; preds = %37
%41 = load i8*, i8** %2
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %4
%44 = call i32 @get_value(i8* %43)
br label %45
45: ; preds = %40, %33
%46 = phi i32 [ %36, %33 ], [ %44, %40 ]
%47 = phi i8** [ %1, %33 ], [ %2, %40 ]
%48 = call i8* @xstrdup(i32 %46)
store i8* %48, i8** %47
br label %49
49: ; preds = %45, %19, %37
%50 = call i32 @getline(i8** %4, i64* %5, i32* %14)
%51 = icmp sgt i32 %50, -1
br i1 %51, label %19, label %52
52: ; preds = %49, %16
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
%55 = call i32 @fclose(i32* %14)
br label %56
56: ; preds = %13, %52
ret void
}