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

/* Variables and functions */
int _inner_expand(char const *, char **, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int expand_domain(const char *c, char **result) {
  if (c == NULL)
    return -1;
  int ret = -1;
  char line[256];
  FILE *fd;
  fd = fopen("/etc/olla.conf", "r");
  if (!fd) {
    return -1;
  }
  int alive = 1;
  while (fgets(line, sizeof(line), fd) != NULL && alive) {
    char *key = strtok(line, ":");
    char *value = strtok(NULL, ":");
    if (key != NULL && value != NULL) {
      int vlen = strlen(value) - 1;
      if (value[vlen] == '\n') {
        value[vlen] = '\0';
      }
      int rez = _inner_expand(c, result, key, value);
      if (rez > 0) {
        alive = 0;
        ret = 1;
      }
    }
  }
  fclose(fd);
  return ret;
}


x86 assembly (clang, -O0):
<expand_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118a <expand_domain+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <expand_domain+0x1a9>
movl   $0xffffffff,-0x1c(%rbp)
lea    0xe68(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11c5 <expand_domain+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <expand_domain+0x1a9>
movl   $0x1,-0x12c(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x149(%rbp)
je     120c <expand_domain+0xac>
cmpl   $0x0,-0x12c(%rbp)
setne  %al
mov    %al,-0x149(%rbp)
mov    -0x149(%rbp),%al
test   $0x1,%al
jne    121f <expand_domain+0xbf>
jmp    12f7 <expand_domain+0x197>
lea    -0x120(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x138(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdcd(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x138(%rbp)
je     12f2 <expand_domain+0x192>
cmpq   $0x0,-0x140(%rbp)
je     12f2 <expand_domain+0x192>
mov    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x144(%rbp)
mov    -0x140(%rbp),%rax
movslq -0x144(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12ae <expand_domain+0x14e>
mov    -0x140(%rbp),%rax
movslq -0x144(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x138(%rbp),%rdx
mov    -0x140(%rbp),%rcx
call   1050 <_inner_expand@plt>
mov    %eax,-0x148(%rbp)
cmpl   $0x0,-0x148(%rbp)
jle    12ed <expand_domain+0x18d>
movl   $0x0,-0x12c(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    12f2 <expand_domain+0x192>
jmp    11cf <expand_domain+0x6f>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_domain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     126c <expand_domain+0x10c>
lea    0xe76(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     126c <expand_domain+0x10c>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     1262 <expand_domain+0x102>
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
lea    0xe37(%rip),%rbp
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
test   %r14,%r14
je     1240 <expand_domain+0xe0>
mov    %rax,%r15
test   %rax,%rax
je     1240 <expand_domain+0xe0>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    1214 <expand_domain+0xb4>
movb   $0x0,-0x1(%r15,%rax,1)
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <_inner_expand@plt>
xor    %ebp,%ebp
test   %eax,%eax
setle  %bpl
mov    $0x1,%eax
cmovg  %eax,%r12d
jmp    1245 <expand_domain+0xe5>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%ebp
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %ebp,%ebp
je     1262 <expand_domain+0x102>
test   %rax,%rax
jne    11d0 <expand_domain+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1272 <expand_domain+0x112>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/etc/olla.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
define i32 @expand_domain(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %73
17: ; preds = %2
store i32 -1, i32* %6
%18 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 -1, i32* %3
br label %73
22: ; preds = %17
store i32 1, i32* %9
br label %23
23: ; preds = %68, %22
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %8
%26 = call i32* @fgets(i8* %24, i32 256, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br label %31
31: ; preds = %28, %23
%32 = phi i1 [ false, %23 ], [ %30, %28 ]
br i1 %32, label %33, label %69
33: ; preds = %31
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = call i8* @strtok(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %35, i8** %10
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %36, i8** %11
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %68
39: ; preds = %33
%40 = load i8*, i8** %11
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %68
42: ; preds = %39
%43 = load i8*, i8** %11
%44 = call i32 @strlen(i8* %43)
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %12
%46 = load i8*, i8** %11
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %58
53: ; preds = %42
%54 = load i8*, i8** %11
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
br label %58
58: ; preds = %53, %42
%59 = load i8*, i8** %4
%60 = load i8**, i8*** %5
%61 = load i8*, i8** %10
%62 = load i8*, i8** %11
%63 = call i32 @_inner_expand(i8* %59, i8** %60, i8* %61, i8* %62)
store i32 %63, i32* %13
%64 = load i32, i32* %13
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %58
store i32 0, i32* %9
store i32 1, i32* %6
br label %67
67: ; preds = %66, %58
br label %68
68: ; preds = %67, %39, %33
br label %23
69: ; preds = %31
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %6
store i32 %72, i32* %3
br label %73
73: ; preds = %69, %21, %16
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [15 x i8] c"/etc/olla.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
define i32 @expand_domain(i8* %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i8* %0, null
br i1 %4, label %45, label %5
5: ; preds = %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %43, label %9
9: ; preds = %5
%10 = call i32* @fgets(i8* %6, i32 256, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %40, label %12
12: ; preds = %9, %33
%13 = phi i32 [ %35, %33 ], [ -1, %9 ]
%14 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i8* %14, null
%17 = icmp ne i8* %15, null
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %33
19: ; preds = %12
%20 = call i32 @strlen(i8* %15)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %15, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %19
store i8 0, i8* %23
br label %27
27: ; preds = %26, %19
%28 = call i32 @_inner_expand(i8* %0, i8** %1, i8* %14, i8* %15)
%29 = icmp sgt i32 %28, 0
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
%32 = select i1 %29, i32 1, i32 %13
br label %33
33: ; preds = %27, %12
%34 = phi i32 [ %31, %27 ], [ 1, %12 ]
%35 = phi i32 [ %32, %27 ], [ %13, %12 ]
%36 = call i32* @fgets(i8* %6, i32 256, i32* %7)
%37 = icmp ne i32* %36, null
%38 = icmp ne i32 %34, 0
%39 = and i1 %38, %37
br i1 %39, label %12, label %40
40: ; preds = %33, %9
%41 = phi i32 [ -1, %9 ], [ %35, %33 ]
%42 = call i32 @fclose(i32* %7)
br label %43
43: ; preds = %5, %40
%44 = phi i32 [ %41, %40 ], [ -1, %5 ]
br label %45
45: ; preds = %2, %43
%46 = phi i32 [ %44, %43 ], [ -1, %2 ]
ret i32 %46
}