#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*/ assert(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ semanage_is_prefix(char *, char const *);
int /*<<< orphan*/ semanage_rtrim(char *, char);
char *semanage_split(char *, char const *);
char *semanage_findval(const char *file, const char *var, const char *delim) {
  FILE *fd;
  char *buff = NULL;
  char *retval = NULL;
  size_t buff_len = 0;
  assert(file);
  assert(var);
  if ((fd = fopen(file, "r")) == NULL)
    return NULL;
  while (getline(&buff, &buff_len, fd) > 0) {
    if (semanage_is_prefix(buff, var)) {
      retval = semanage_split(buff, delim);
      if (retval)
        semanage_rtrim(retval, '\n');
      break;
    }
  }
  free(buff);
  fclose(fd);
  return retval;
}


x86 assembly (clang, -O0):
<semanage_findval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e9 <semanage_findval+0x69>
movq   $0x0,-0x8(%rbp)
jmp    126e <semanage_findval+0xee>
jmp    11ee <semanage_findval+0x6e>
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0x0,%rax
jle    1254 <semanage_findval+0xd4>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <semanage_is_prefix@plt>
cmp    $0x0,%rax
je     124f <semanage_findval+0xcf>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <semanage_split@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     124a <semanage_findval+0xca>
mov    -0x38(%rbp),%rdi
mov    $0xa,%esi
call   1050 <semanage_rtrim@plt>
jmp    1254 <semanage_findval+0xd4>
jmp    11ee <semanage_findval+0x6e>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semanage_findval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1060 <assert@plt>
lea    0xe43(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1229 <semanage_findval+0xa9>
mov    %rax,%r12
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1090 <getline@plt>
test   %rax,%rax
jle    1231 <semanage_findval+0xb1>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <semanage_is_prefix@plt>
test   %rax,%rax
je     11e0 <semanage_findval+0x60>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1070 <semanage_split@plt>
test   %rax,%rax
je     122e <semanage_findval+0xae>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <semanage_rtrim@plt>
jmp    1231 <semanage_findval+0xb1>
xor    %r14d,%r14d
jmp    1243 <semanage_findval+0xc3>
xor    %r14d,%r14d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%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"
define i8* @semanage_findval(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %9
store i8* null, i8** %10
store i64 0, i64* %11
%12 = load i8*, i8** %5
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %6
%15 = call i32 @assert(i8* %14)
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %3
store i8* null, i8** %4
br label %47
20: ; preds = %3
br label %21
21: ; preds = %40, %20
%22 = load i32*, i32** %8
%23 = call i64 @getline(i8** %9, i64* %11, i32* %22)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i8*, i8** %9
%27 = load i8*, i8** %6
%28 = call i64 @semanage_is_prefix(i8* %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %25
%31 = load i8*, i8** %9
%32 = load i8*, i8** %7
%33 = call i8* @semanage_split(i8* %31, i8* %32)
store i8* %33, i8** %10
%34 = load i8*, i8** %10
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i8*, i8** %10
%38 = call i32 @semanage_rtrim(i8* %37, i8 signext 10)
br label %39
39: ; preds = %36, %30
br label %41
40: ; preds = %25
br label %21
41: ; preds = %39, %21
%42 = load i8*, i8** %9
%43 = call i32 @free(i8* %42)
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %10
store i8* %46, i8** %4
br label %47
47: ; preds = %41, %19
%48 = load i8*, i8** %4
ret i8* %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @semanage_findval(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = tail call i32 @assert(i8* %0)
%9 = tail call i32 @assert(i8* %1)
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %30, label %12
12: ; preds = %3, %15
%13 = call i64 @getline(i8** %4, i64* %5, i32* %10)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i64 @semanage_is_prefix(i8* %16, i8* %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i8* @semanage_split(i8* %20, i8* %2)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @semanage_rtrim(i8* %21, i8 signext 10)
br label %25
25: ; preds = %12, %19, %23
%26 = phi i8* [ %21, %23 ], [ null, %19 ], [ null, %12 ]
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = call i32 @fclose(i32* %10)
br label %30
30: ; preds = %3, %25
%31 = phi i8* [ %26, %25 ], [ null, %3 ]
ret i8* %31
}