#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int parse_conf_opt(char *buf, char *option, char *value) {
  char *ptr, *ptr2, *tmp;
  int n;
  char fmt[256];
  strcpy(fmt, option);
  strcat(fmt, " = %s");
  char *line = strtok((tmp = strdup(buf)), "\n");
  while (line) {
    ptr = strstr(line, option);
    ptr2 = strstr(line, "#");
    if (ptr && ptr2 && ptr2 < ptr)
      goto next_line;
    if (ptr) {
      n = sscanf(ptr, fmt, value);
      if (n == 1) {
        free(tmp);
        return 1;
      }
    }
  next_line:
    line = strtok(NULL, "\n");
  }
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<parse_conf_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x140(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
lea    0xe45(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
je     1296 <parse_conf_opt+0x126>
mov    -0x148(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x148(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     122f <parse_conf_opt+0xbf>
cmpq   $0x0,-0x30(%rbp)
je     122f <parse_conf_opt+0xbf>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    122f <parse_conf_opt+0xbf>
jmp    127a <parse_conf_opt+0x10a>
cmpq   $0x0,-0x28(%rbp)
je     1275 <parse_conf_opt+0x105>
mov    -0x28(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jne    1270 <parse_conf_opt+0x100>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <parse_conf_opt+0x136>
jmp    1275 <parse_conf_opt+0x105>
jmp    127a <parse_conf_opt+0x10a>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd81(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x148(%rbp)
jmp    11cd <parse_conf_opt+0x5d>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_conf_opt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1040 <strcpy@plt>
lea    0xe52(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %rbp,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbp
lea    0xe3e(%rip),%rsi
mov    %rax,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
je     1248 <parse_conf_opt+0xc8>
mov    %rax,%r15
lea    0xe22(%rip),%r12
lea    0x10(%rsp),%r13
jmp    121c <parse_conf_opt+0x9c>
nopl   0x0(%rax,%rax,1)
test   %rbp,%rbp
je     1208 <parse_conf_opt+0x88>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     124c <parse_conf_opt+0xcc>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
je     1251 <parse_conf_opt+0xd1>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strstr@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
test   %rbp,%rbp
je     11f0 <parse_conf_opt+0x70>
test   %rax,%rax
je     11f0 <parse_conf_opt+0x70>
cmp    %rbp,%rax
jae    11f5 <parse_conf_opt+0x75>
jmp    1208 <parse_conf_opt+0x88>
xor    %ebp,%ebp
jmp    1251 <parse_conf_opt+0xd1>
mov    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c" = %s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c"#\00"
define i32 @parse_conf_opt(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %5
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %10
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %13
br label %22
22: ; preds = %56, %3
%23 = load i8*, i8** %13
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %58
25: ; preds = %22
%26 = load i8*, i8** %13
%27 = load i8*, i8** %6
%28 = call i8* @strstr(i8* %26, i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %13
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %30, i8** %9
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %25
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %9
%38 = load i8*, i8** %8
%39 = icmp ult i8* %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
br label %56
41: ; preds = %36, %33, %25
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = load i8*, i8** %8
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%47 = load i8*, i8** %7
%48 = call i32 @sscanf(i8* %45, i8* %46, i8* %47)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = load i8*, i8** %10
%53 = call i32 @free(i8* %52)
store i32 1, i32* %4
br label %61
54: ; preds = %44
br label %55
55: ; preds = %54, %41
br label %56
56: ; preds = %55, %40
%57 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %57, i8** %13
br label %22
58: ; preds = %22
%59 = load i8*, i8** %10
%60 = call i32 @free(i8* %59)
store i32 0, i32* %4
br label %61
61: ; preds = %58, %51
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [6 x i8] c" = %s\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @parse_conf_opt(i8* nocapture %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 = call i32 @strcpy(i8* %5, i8* %1)
%7 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = call i8* @strdup(i8* %0)
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %27, label %11
11: ; preds = %3, %24
%12 = phi i8* [ %25, %24 ], [ %9, %3 ]
%13 = call i8* @strstr(i8* %12, i8* dereferenceable(1) %1)
%14 = call i8* @strchr(i8* %12, i32 35)
%15 = icmp ne i8* %13, null
%16 = icmp ne i8* %14, null
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = icmp ult i8* %14, %13
br i1 %19, label %24, label %21
20: ; preds = %11
br i1 %15, label %21, label %24
21: ; preds = %18, %20
%22 = call i32 @sscanf(i8* %13, i8* %5, i8* %2)
%23 = icmp eq i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %20, %21, %18
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %11
27: ; preds = %24, %21, %3
%28 = phi i32 [ 0, %3 ], [ 1, %21 ], [ 0, %24 ]
%29 = call i32 @free(i8* %8)
ret i32 %28
}