#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *readconf(char *fname, char *name, char *out) {
  char rbuf[1024];
  FILE *f;
  out[0] = 0;
  f = fopen(fname, "rb");
  if (!f) {
    fprintf(stderr, "no such config file: '%s'\n", fname);
    return NULL;
  }
  while (fgets(rbuf, 1024, f)) {
    char *buf = rbuf;
    while (*buf && (*buf <= ' '))
      buf++;
    if (*buf == '#')
      continue;
    if (!strncmp(name, buf, strlen(name))) {
      char *ptr = buf + strlen(buf);
      while ((ptr > buf) && (*ptr <= ' '))
        *ptr-- = 0;
      ptr = buf + strlen(name);
      while (*ptr && (*ptr <= ' '))
        ptr++;
      strncpy(out, ptr, 256);
    }
  }
  if (!strlen(out)) {
    fprintf(stderr, "can't find variable: '%s' in config file: '%s'\n", name,
            fname);
    return NULL;
  }
  fclose(f);
  return out;
}


x86 assembly (clang, -O0):
<readconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11db <readconf+0x6b>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1449 <readconf+0x2d9>
jmp    11e0 <readconf+0x70>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     13f7 <readconf+0x287>
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x439(%rbp)
je     1241 <readconf+0xd1>
mov    -0x430(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setle  %al
mov    %al,-0x439(%rbp)
mov    -0x439(%rbp),%al
test   $0x1,%al
jne    1254 <readconf+0xe4>
jmp    126b <readconf+0xfb>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    1210 <readconf+0xa0>
mov    -0x430(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1283 <readconf+0x113>
jmp    11e0 <readconf+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x450(%rbp),%rdi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    13f2 <readconf+0x282>
mov    -0x430(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x430(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x458(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rcx
xor    %eax,%eax
cmp    -0x430(%rbp),%rcx
mov    %al,-0x459(%rbp)
jbe    1325 <readconf+0x1b5>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setle  %al
mov    %al,-0x459(%rbp)
mov    -0x459(%rbp),%al
test   $0x1,%al
jne    1338 <readconf+0x1c8>
jmp    1355 <readconf+0x1e5>
mov    -0x438(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x438(%rbp)
movb   $0x0,(%rax)
jmp    12f3 <readconf+0x183>
mov    -0x430(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x468(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x469(%rbp)
je     13b3 <readconf+0x243>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setle  %al
mov    %al,-0x469(%rbp)
mov    -0x469(%rbp),%al
test   $0x1,%al
jne    13c6 <readconf+0x256>
jmp    13dd <readconf+0x26d>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
jmp    1382 <readconf+0x212>
mov    -0x20(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    11e0 <readconf+0x70>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jne    1435 <readconf+0x2c5>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xbfd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1449 <readconf+0x2d9>
mov    -0x428(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readconf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
movb   $0x0,(%rdx)
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     129f <readconf+0x12f>
mov    %rax,%rbx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1289 <readconf+0x119>
mov    %r13,%rcx
jmp    11fc <readconf+0x8c>
mov    %r15,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r13,%rcx
test   %rax,%rax
je     1289 <readconf+0x119>
mov    %rcx,%rbp
mov    (%rcx),%al
test   %al,%al
je     120d <readconf+0x9d>
lea    0x1(%rbp),%rcx
cmp    $0x21,%al
jl     11fc <readconf+0x8c>
cmp    $0x23,%al
je     11e0 <readconf+0x70>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11e0 <readconf+0x70>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1251 <readconf+0xe1>
mov    %eax,%eax
add    %rbp,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rax)
jg     1251 <readconf+0xe1>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbp,%rax
ja     1240 <readconf+0xd0>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rsi
add    $0xffffffffffffffff,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rsi),%eax
add    $0x1,%rsi
test   %al,%al
je     11c6 <readconf+0x56>
cmp    $0x21,%al
jl     1270 <readconf+0x100>
jmp    11c6 <readconf+0x56>
mov    %r15,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     12be <readconf+0x14e>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12de <readconf+0x16e>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12de <readconf+0x16e>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
xor    %r15d,%r15d
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"no such config file: '%s'\0A\00"
@.str.2 = [48 x i8] c"can't find variable: '%s' in config file: '%s'\0A\00"
define i8* @readconf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i8* null, i8** %4
br label %117
22: ; preds = %3
br label %23
23: ; preds = %103, %50, %22
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = load i32*, i32** %9
%26 = call i64 @fgets(i8* %24, i32 1024, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %104
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %29, i8** %10
br label %30
30: ; preds = %42, %28
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %10
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp sle i32 %38, 32
br label %40
40: ; preds = %35, %30
%41 = phi i1 [ false, %30 ], [ %39, %35 ]
br i1 %41, label %42, label %45
42: ; preds = %40
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %10
br label %30
45: ; preds = %40
%46 = load i8*, i8** %10
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 35
br i1 %49, label %50, label %51
50: ; preds = %45
br label %23
51: ; preds = %45
%52 = load i8*, i8** %6
%53 = load i8*, i8** %10
%54 = load i8*, i8** %6
%55 = call i32 @strlen(i8* %54)
%56 = call i32 @strncmp(i8* %52, i8* %53, i32 %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %103, label %58
58: ; preds = %51
%59 = load i8*, i8** %10
%60 = load i8*, i8** %10
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8* %63, i8** %11
br label %64
64: ; preds = %75, %58
%65 = load i8*, i8** %11
%66 = load i8*, i8** %10
%67 = icmp ugt i8* %65, %66
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8*, i8** %11
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp sle i32 %71, 32
br label %73
73: ; preds = %68, %64
%74 = phi i1 [ false, %64 ], [ %72, %68 ]
br i1 %74, label %75, label %78
75: ; preds = %73
%76 = load i8*, i8** %11
%77 = getelementptr inbounds i8, i8* %76, i32 -1
store i8* %77, i8** %11
store i8 0, i8* %76
br label %64
78: ; preds = %73
%79 = load i8*, i8** %10
%80 = load i8*, i8** %6
%81 = call i32 @strlen(i8* %80)
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
store i8* %83, i8** %11
br label %84
84: ; preds = %96, %78
%85 = load i8*, i8** %11
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %84
%90 = load i8*, i8** %11
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp sle i32 %92, 32
br label %94
94: ; preds = %89, %84
%95 = phi i1 [ false, %84 ], [ %93, %89 ]
br i1 %95, label %96, label %99
96: ; preds = %94
%97 = load i8*, i8** %11
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %11
br label %84
99: ; preds = %94
%100 = load i8*, i8** %7
%101 = load i8*, i8** %11
%102 = call i32 @strncpy(i8* %100, i8* %101, i32 256)
br label %103
103: ; preds = %99, %51
br label %23
104: ; preds = %23
%105 = load i8*, i8** %7
%106 = call i32 @strlen(i8* %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %113, label %108
108: ; preds = %104
%109 = load i32, i32* @stderr
%110 = load i8*, i8** %6
%111 = load i8*, i8** %5
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %110, i8* %111)
store i8* null, i8** %4
br label %117
113: ; preds = %104
%114 = load i32*, i32** %9
%115 = call i32 @fclose(i32* %114)
%116 = load i8*, i8** %7
store i8* %116, i8** %4
br label %117
117: ; preds = %113, %108, %18
%118 = load i8*, i8** %4
ret i8* %118
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"no such config file: '%s'\0A\00"
@.str.2 = [48 x i8] c"can't find variable: '%s' in config file: '%s'\0A\00"
define i8* @readconf(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 0, i8* %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %58, label %14
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %66
14: ; preds = %8, %21
%15 = phi i8* [ %22, %21 ], [ %5, %8 ]
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = icmp slt i8 %16, 33
%19 = and i1 %17, %18
%20 = getelementptr inbounds i8, i8* %15, i64 1
br i1 %19, label %21, label %23
21: ; preds = %14, %55
%22 = phi i8* [ %20, %14 ], [ %5, %55 ]
br label %14
23: ; preds = %14
%24 = icmp eq i8 %16, 35
br i1 %24, label %55, label %25
25: ; preds = %23
%26 = call i32 @strlen(i8* %1)
%27 = call i32 @strncmp(i8* %1, i8* %15, i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %55
29: ; preds = %25
%30 = call i32 @strlen(i8* %15)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = zext i32 %30 to i64
%34 = getelementptr inbounds i8, i8* %15, i64 %33
br label %35
35: ; preds = %32, %39
%36 = phi i8* [ %40, %39 ], [ %34, %32 ]
%37 = load i8, i8* %36
%38 = icmp slt i8 %37, 33
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %36, i64 -1
store i8 0, i8* %36
%41 = icmp ugt i8* %40, %15
br i1 %41, label %35, label %42
42: ; preds = %35, %39, %29
%43 = call i32 @strlen(i8* %1)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %15, i64 %44
br label %46
46: ; preds = %46, %42
%47 = phi i8* [ %45, %42 ], [ %52, %46 ]
%48 = load i8, i8* %47
%49 = icmp ne i8 %48, 0
%50 = icmp slt i8 %48, 33
%51 = and i1 %49, %50
%52 = getelementptr inbounds i8, i8* %47, i64 1
br i1 %51, label %46, label %53
53: ; preds = %46
%54 = call i32 @strncpy(i8* %2, i8* %47, i32 256)
br label %55
55: ; preds = %25, %53, %23
%56 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %21
58: ; preds = %55, %8
%59 = call i32 @strlen(i8* %2)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0)
br label %66
64: ; preds = %58
%65 = call i32 @fclose(i32* %6)
br label %66
66: ; preds = %64, %61, %11
%67 = phi i8* [ %2, %64 ], [ null, %61 ], [ null, %11 ]
ret i8* %67
}