#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *i8086OpenConfig(char const *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char const *, int);
int i8086ReadStrConfig(char *buf, const char *filename, const char *name) {
  FILE *file;
  char str[256];
  char *value;
  int ret = 0;
  file = i8086OpenConfig(filename);
  buf[0] = '\0';
  if (file != NULL) {
    while (fgets(str, 256, file) != NULL) {
      if (str[0] != '#' && str[0] != '\0') {
        value = strchr(str, '=');
        if (value != NULL && strlen(value) > 1) {
          if (value[strlen(value) - 1] == '\n')
            value[strlen(value) - 1] = '\0';
          if (value[strlen(value) - 1] == '\r')
            value[strlen(value) - 1] = '\0';
          value = strchr(value, value[1]);
          if ((strlen(value) > 0) &&
              (strncmp(str, name, strlen(str) - strlen(value) - 1) == 0)) {
            strcpy(buf, value);
            ret = 1;
            break;
          }
        }
      }
    }
    fclose(file);
  }
  return ret;
}


x86 assembly (clang, -O0):
<i8086ReadStrConfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <i8086OpenConfig@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     13be <i8086ReadStrConfig+0x24e>
jmp    11b5 <i8086ReadStrConfig+0x45>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13b5 <i8086ReadStrConfig+0x245>
movsbl -0x120(%rbp),%eax
cmp    $0x23,%eax
je     13b0 <i8086ReadStrConfig+0x240>
movsbl -0x120(%rbp),%eax
cmp    $0x0,%eax
je     13b0 <i8086ReadStrConfig+0x240>
lea    -0x120(%rbp),%rdi
mov    $0x3d,%esi
call   1080 <strchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     13ab <i8086ReadStrConfig+0x23b>
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jle    13ab <i8086ReadStrConfig+0x23b>
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x138(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1292 <i8086ReadStrConfig+0x122>
mov    -0x128(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x140(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x128(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    12f5 <i8086ReadStrConfig+0x185>
mov    -0x128(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x150(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x128(%rbp),%rdi
mov    -0x128(%rbp),%rax
movsbl 0x1(%rax),%esi
call   1080 <strchr@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%eax
jle    13a6 <i8086ReadStrConfig+0x236>
lea    -0x120(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x164(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x164(%rbp),%edx
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rsi
sub    %eax,%edx
sub    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13a6 <i8086ReadStrConfig+0x236>
mov    -0x8(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1050 <strcpy@plt>
movl   $0x1,-0x12c(%rbp)
jmp    13b5 <i8086ReadStrConfig+0x245>
jmp    13ab <i8086ReadStrConfig+0x23b>
jmp    13b0 <i8086ReadStrConfig+0x240>
jmp    11b5 <i8086ReadStrConfig+0x45>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x12c(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i8086ReadStrConfig>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,0x8(%rsp)
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <i8086OpenConfig@plt>
movb   $0x0,(%r14)
test   %rax,%rax
je     12c3 <i8086ReadStrConfig+0x153>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     12b9 <i8086ReadStrConfig+0x149>
lea    0x10(%rsp),%r13
jmp    11e9 <i8086ReadStrConfig+0x79>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12b9 <i8086ReadStrConfig+0x149>
movzbl 0x10(%rsp),%eax
test   %al,%al
je     11d0 <i8086ReadStrConfig+0x60>
cmp    $0x23,%al
je     11d0 <i8086ReadStrConfig+0x60>
mov    %r13,%rdi
mov    $0x3d,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     11d0 <i8086ReadStrConfig+0x60>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jl     11d0 <i8086ReadStrConfig+0x60>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1238 <i8086ReadStrConfig+0xc8>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xd,-0x1(%rax,%rbp,1)
jne    1258 <i8086ReadStrConfig+0xe8>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
movsbl 0x1(%rbp),%esi
mov    %rbp,%rdi
call   1080 <strchr@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <strlen@plt>
test   %eax,%eax
jle    11d0 <i8086ReadStrConfig+0x60>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <strlen@plt>
not    %eax
add    %eax,%r15d
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
mov    %r15d,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11d0 <i8086ReadStrConfig+0x60>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
mov    $0x1,%r12d
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    12c6 <i8086ReadStrConfig+0x156>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i8086ReadStrConfig(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = call i32* @i8086OpenConfig(i8* %11)
store i32* %12, i32** %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %106
17: ; preds = %3
br label %18
18: ; preds = %102, %17
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %7
%21 = call i32* @fgets(i8* %19, i32 256, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %103
23: ; preds = %18
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 35
br i1 %27, label %28, label %102
28: ; preds = %23
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %102
33: ; preds = %28
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = call i8* @strchr(i8* %34, i8 signext 61)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %101
38: ; preds = %33
%39 = load i8*, i8** %9
%40 = call i32 @strlen(i8* %39)
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %101
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = load i8*, i8** %9
%45 = call i32 @strlen(i8* %44)
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 10
br i1 %51, label %52, label %59
52: ; preds = %42
%53 = load i8*, i8** %9
%54 = load i8*, i8** %9
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %53, i64 %57
store i8 0, i8* %58
br label %59
59: ; preds = %52, %42
%60 = load i8*, i8** %9
%61 = load i8*, i8** %9
%62 = call i32 @strlen(i8* %61)
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %60, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 13
br i1 %68, label %69, label %76
69: ; preds = %59
%70 = load i8*, i8** %9
%71 = load i8*, i8** %9
%72 = call i32 @strlen(i8* %71)
%73 = sub nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %70, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %69, %59
%77 = load i8*, i8** %9
%78 = load i8*, i8** %9
%79 = getelementptr inbounds i8, i8* %78, i64 1
%80 = load i8, i8* %79
%81 = call i8* @strchr(i8* %77, i8 signext %80)
store i8* %81, i8** %9
%82 = load i8*, i8** %9
%83 = call i32 @strlen(i8* %82)
%84 = icmp sgt i32 %83, 0
br i1 %84, label %85, label %100
85: ; preds = %76
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%87 = load i8*, i8** %6
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%89 = call i32 @strlen(i8* %88)
%90 = load i8*, i8** %9
%91 = call i32 @strlen(i8* %90)
%92 = sub nsw i32 %89, %91
%93 = sub nsw i32 %92, 1
%94 = call i64 @strncmp(i8* %86, i8* %87, i32 %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %85
%97 = load i8*, i8** %4
%98 = load i8*, i8** %9
%99 = call i32 @strcpy(i8* %97, i8* %98)
store i32 1, i32* %10
br label %103
100: ; preds = %85, %76
br label %101
101: ; preds = %100, %38, %33
br label %102
102: ; preds = %101, %28, %23
br label %18
103: ; preds = %96, %18
%104 = load i32*, i32** %7
%105 = call i32 @fclose(i32* %104)
br label %106
106: ; preds = %103, %3
%107 = load i32, i32* %10
ret i32 %107
}

LLVM IR (-O2):
define i32 @i8086ReadStrConfig(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @i8086OpenConfig(i8* %1)
store i8 0, i8* %0
%7 = icmp eq i32* %6, null
br i1 %7, label %64, label %8
8: ; preds = %3
%9 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %61, label %11
11: ; preds = %8, %58
%12 = load i8, i8* %5
switch i8 %12, label %13 [
i8 35, label %58
i8 0, label %58
]
13: ; preds = %11
%14 = call i8* @strchr(i8* %5, i8 signext 61)
%15 = icmp eq i8* %14, null
br i1 %15, label %58, label %16
16: ; preds = %13
%17 = call i32 @strlen(i8* %14)
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %58
19: ; preds = %16
%20 = call i32 @strlen(i8* %14)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = call i32 @strlen(i8* %14)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %14, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %26, %19
%32 = call i32 @strlen(i8* %14)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %14, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 13
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = call i32 @strlen(i8* %14)
%40 = add nsw i32 %39, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %14, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %38, %31
%44 = getelementptr inbounds i8, i8* %14, i64 1
%45 = load i8, i8* %44
%46 = call i8* @strchr(i8* %14, i8 signext %45)
%47 = call i32 @strlen(i8* %46)
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %43
%50 = call i32 @strlen(i8* %5)
%51 = call i32 @strlen(i8* %46)
%52 = xor i32 %51, -1
%53 = add i32 %50, %52
%54 = call i64 @strncmp(i8* %5, i8* %2, i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %49
%57 = call i32 @strcpy(i8* %0, i8* %46)
br label %61
58: ; preds = %11, %11, %13, %16, %49, %43
%59 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %11
61: ; preds = %58, %8, %56
%62 = phi i32 [ 1, %56 ], [ 0, %8 ], [ 0, %58 ]
%63 = call i32 @fclose(i32* %6)
br label %64
64: ; preds = %61, %3
%65 = phi i32 [ %62, %61 ], [ 0, %3 ]
ret i32 %65
}