#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 union val {
  int dummy;
} val;

/* Variables and functions */
scalar_t__ readname(char const *, char *);
char *strchr(char const *, char);
int strtoval(char *, union val *);
int readopt(const char *line, char *key, union val *val, int *tp) {
  char *p;
  if (line[0] == '\n')
    return 0;
  if (readname(line, key)) {
    if (line[0] == '[')
      return 1;
    if (p = strchr(line, '=')) {
      *tp = strtoval(p + 1, val);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1164 <readopt+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <readopt+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <readname@plt>
cmp    $0x0,%rax
je     11dd <readopt+0xad>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1197 <readopt+0x67>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <readopt+0xb4>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11d8 <readopt+0xa8>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strtoval@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11e4 <readopt+0xb4>
jmp    11dd <readopt+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readopt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
cmpb   $0xa,(%rdi)
je     117f <readopt+0x4f>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
call   1040 <readname@plt>
test   %rax,%rax
je     117f <readopt+0x4f>
cmpb   $0x5b,(%rbx)
je     117a <readopt+0x4a>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117f <readopt+0x4f>
add    $0x1,%rax
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strtoval@plt>
mov    %eax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.val = type { i32 }
define i32 @readopt(i8* %0, i8* %1, %union.val* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %union.val*
%9 = alloca i32*
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store %union.val* %2, %union.val** %8
store i32* %3, i32** %9
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 0, i32* %5
br label %41
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = call i64 @readname(i8* %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 91
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %5
br label %41
29: ; preds = %22
%30 = load i8*, i8** %6
%31 = call i8* @strchr(i8* %30, i8 signext 61)
store i8* %31, i8** %10
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load %union.val*, %union.val** %8
%37 = call i32 @strtoval(i8* %35, %union.val* %36)
%38 = load i32*, i32** %9
store i32 %37, i32* %38
store i32 1, i32* %5
br label %41
39: ; preds = %29
br label %40
40: ; preds = %39, %17
store i32 0, i32* %5
br label %41
41: ; preds = %40, %33, %28, %16
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%union.val = type { i32 }
define i32 @readopt(i8* %0, i8* %1, %union.val* %2, i32* nocapture writeonly %3) {
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 10
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = tail call i64 @readname(i8* %0, i8* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 91
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = tail call i8* @strchr(i8* %0, i8 signext 61)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = tail call i32 @strtoval(i8* %17, %union.val* %2)
store i32 %18, i32* %3
br label %19
19: ; preds = %7, %13, %10, %4, %16
%20 = phi i32 [ 1, %16 ], [ 0, %4 ], [ 1, %10 ], [ 0, %13 ], [ 0, %7 ]
ret i32 %20
}