#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 */
struct confctl {
  int dummy;
};
struct buf {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ buf_append(struct buf *, int);
int /*<<< orphan*/ buf_finish(struct buf *);
int buf_last(struct buf *);
struct buf *buf_new();
int buf_read_slashed(struct buf *, struct confctl const *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ buf_read_until_newline(struct buf *, int /*<<< orphan*/ *);
int /*<<< orphan*/ buf_strip(struct buf *);
int getc(int /*<<< orphan*/ *);
scalar_t__ isspace(int);
int /*<<< orphan*/ ungetc_checked(int, int /*<<< orphan*/ *);
struct buf *buf_read_before(const struct confctl *cc, FILE *fp,
                            bool *closing_bracket) {
  int ch;
  struct buf *b;
  bool no_newline = false, comment_parsed;
  *closing_bracket = false;
  b = buf_new();
  for (;;) {
    ch = getc(fp);
    if (ch == EOF) {
      *closing_bracket = true;
      break;
    }
    if (no_newline && (ch == '\n' || ch == '\r' || ch == '}'))
      goto unget;
    if (ch == '/') {
      buf_append(b, ch);
      comment_parsed = buf_read_slashed(b, cc, fp);
      if (!comment_parsed) {
        buf_strip(b);
        goto unget;
      }
      if (no_newline) {
        ch = buf_last(b);
        if (ch == '\n' || ch == '\r') {
          buf_strip(b);
          goto unget;
        }
      }
      continue;
    }
    if (ch == '#') {
      buf_append(b, ch);
      buf_read_until_newline(b, fp);
      if (no_newline) {
        ch = buf_last(b);
        buf_strip(b);
        goto unget;
      }
      continue;
    }
    if (ch == '}') {
      no_newline = true;
      *closing_bracket = true;
      buf_append(b, ch);
      continue;
    }
    if (isspace(ch) || ch == ';') {
      buf_append(b, ch);
      continue;
    }
  unget:
    ungetc_checked(ch, fp);
    break;
  }
  buf_finish(b);
  return (b);
}


x86 assembly (clang, -O0):
<buf_read_before>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1040 <buf_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e02(%rip),%rcx
cmp    (%rcx),%eax
jne    11fd <buf_read_before+0x5d>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1364 <buf_read_before+0x1c4>
cmpl   $0x0,-0x2c(%rbp)
je     122a <buf_read_before+0x8a>
cmpl   $0xa,-0x1c(%rbp)
je     1225 <buf_read_before+0x85>
cmpl   $0xd,-0x1c(%rbp)
je     1225 <buf_read_before+0x85>
cmpl   $0x7d,-0x1c(%rbp)
jne    122a <buf_read_before+0x8a>
jmp    1358 <buf_read_before+0x1b8>
cmpl   $0x2f,-0x1c(%rbp)
jne    12ae <buf_read_before+0x10e>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <buf_append@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10c0 <buf_read_slashed@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    126c <buf_read_before+0xcc>
mov    -0x28(%rbp),%rdi
call   1060 <buf_strip@plt>
jmp    1358 <buf_read_before+0x1b8>
cmpl   $0x0,-0x2c(%rbp)
je     12a9 <buf_read_before+0x109>
mov    -0x28(%rbp),%rdi
call   1090 <buf_last@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
je     1296 <buf_read_before+0xf6>
cmpl   $0xd,-0x1c(%rbp)
jne    12a4 <buf_read_before+0x104>
mov    -0x28(%rbp),%rdi
call   1060 <buf_strip@plt>
jmp    1358 <buf_read_before+0x1b8>
jmp    12a9 <buf_read_before+0x109>
jmp    11d0 <buf_read_before+0x30>
cmpl   $0x23,-0x1c(%rbp)
jne    12fa <buf_read_before+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <buf_append@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <buf_read_until_newline@plt>
cmpl   $0x0,-0x2c(%rbp)
je     12f5 <buf_read_before+0x155>
mov    -0x28(%rbp),%rdi
call   1090 <buf_last@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <buf_strip@plt>
jmp    1358 <buf_read_before+0x1b8>
jmp    11d0 <buf_read_before+0x30>
cmpl   $0x7d,-0x1c(%rbp)
jne    1326 <buf_read_before+0x186>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <buf_append@plt>
jmp    11d0 <buf_read_before+0x30>
mov    -0x1c(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
jne    1342 <buf_read_before+0x1a2>
cmpl   $0x3b,-0x1c(%rbp)
jne    1353 <buf_read_before+0x1b3>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <buf_append@plt>
jmp    11d0 <buf_read_before+0x30>
jmp    1358 <buf_read_before+0x1b8>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <ungetc_checked@plt>
mov    -0x28(%rbp),%rdi
call   1030 <buf_finish@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_read_before>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,(%rsp)
movl   $0x0,(%rdx)
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <buf_new@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    0x2e11(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    11eb <buf_read_before+0x4b>
mov    (%rsp),%rax
movl   $0x1,(%rax)
jmp    131a <buf_read_before+0x17a>
mov    %eax,%ebx
jmp    1209 <buf_read_before+0x69>
nop
mov    %r13,%rdi
mov    %ebx,%esi
call   10a0 <buf_append@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebx
cmp    0x0(%rbp),%eax
je     11dc <buf_read_before+0x3c>
test   %r15d,%r15d
je     1230 <buf_read_before+0x90>
lea    -0xa(%rbx),%eax
cmp    $0x25,%eax
ja     12b7 <buf_read_before+0x117>
lea    0xddf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
nopw   0x0(%rax,%rax,1)
cmp    $0x2f,%ebx
je     1270 <buf_read_before+0xd0>
cmp    $0x23,%ebx
je     12d7 <buf_read_before+0x137>
cmp    $0x7d,%ebx
jne    12bc <buf_read_before+0x11c>
mov    (%rsp),%rax
movl   $0x1,(%rax)
mov    %r13,%rdi
mov    $0x7d,%esi
call   10a0 <buf_append@plt>
mov    $0x1,%r15d
jmp    11fa <buf_read_before+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2f,%ebx
mov    %r13,%rdi
mov    $0x2f,%esi
call   10a0 <buf_append@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10c0 <buf_read_slashed@plt>
test   %eax,%eax
je     1308 <buf_read_before+0x168>
test   %r15d,%r15d
je     11fa <buf_read_before+0x5a>
mov    %r13,%rdi
call   1090 <buf_last@plt>
mov    %eax,%ebx
cmp    $0xa,%eax
je     1308 <buf_read_before+0x168>
cmp    $0xd,%ebx
jne    11fa <buf_read_before+0x5a>
jmp    1308 <buf_read_before+0x168>
cmp    $0x7d,%ebx
je     1310 <buf_read_before+0x170>
mov    %ebx,%edi
call   1050 <isspace@plt>
cmp    $0x3b,%ebx
je     11f0 <buf_read_before+0x50>
test   %rax,%rax
jne    11f0 <buf_read_before+0x50>
jmp    1310 <buf_read_before+0x170>
mov    %r13,%rdi
mov    $0x23,%esi
call   10a0 <buf_append@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <buf_read_until_newline@plt>
test   %r15d,%r15d
mov    $0x0,%r15d
je     11fa <buf_read_before+0x5a>
mov    %r13,%rdi
call   1090 <buf_last@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <buf_strip@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <ungetc_checked@plt>
mov    %r13,%rdi
call   1030 <buf_finish@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buf = type { i32 }
%struct.confctl = type { i32 }
@EOF = global i32 0
define %struct.buf* @buf_read_before(%struct.confctl* %0, i32* %1, i32* %2) {
%4 = alloca %struct.confctl*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.buf*
%9 = alloca i32
%10 = alloca i32
store %struct.confctl* %0, %struct.confctl** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %9
%11 = load i32*, i32** %6
store i32 0, i32* %11
%12 = call %struct.buf* (...) @buf_new()
store %struct.buf* %12, %struct.buf** %8
br label %13
13: ; preds = %99, %87, %83, %65, %3
%14 = load i32*, i32** %5
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32*, i32** %6
store i32 1, i32* %20
br label %108
21: ; preds = %13
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 10
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 13
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 125
br i1 %32, label %33, label %34
33: ; preds = %30, %27, %24
br label %104
34: ; preds = %30, %21
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %66
37: ; preds = %34
%38 = load %struct.buf*, %struct.buf** %8
%39 = load i32, i32* %7
%40 = call i32 @buf_append(%struct.buf* %38, i32 %39)
%41 = load %struct.buf*, %struct.buf** %8
%42 = load %struct.confctl*, %struct.confctl** %4
%43 = load i32*, i32** %5
%44 = call i32 @buf_read_slashed(%struct.buf* %41, %struct.confctl* %42, i32* %43)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp ne i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %37
%48 = load %struct.buf*, %struct.buf** %8
%49 = call i32 @buf_strip(%struct.buf* %48)
br label %104
50: ; preds = %37
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %65
53: ; preds = %50
%54 = load %struct.buf*, %struct.buf** %8
%55 = call i32 @buf_last(%struct.buf* %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 10
br i1 %57, label %61, label %58
58: ; preds = %53
%59 = load i32, i32* %7
%60 = icmp eq i32 %59, 13
br i1 %60, label %61, label %64
61: ; preds = %58, %53
%62 = load %struct.buf*, %struct.buf** %8
%63 = call i32 @buf_strip(%struct.buf* %62)
br label %104
64: ; preds = %58
br label %65
65: ; preds = %64, %50
br label %13
66: ; preds = %34
%67 = load i32, i32* %7
%68 = icmp eq i32 %67, 35
br i1 %68, label %69, label %84
69: ; preds = %66
%70 = load %struct.buf*, %struct.buf** %8
%71 = load i32, i32* %7
%72 = call i32 @buf_append(%struct.buf* %70, i32 %71)
%73 = load %struct.buf*, %struct.buf** %8
%74 = load i32*, i32** %5
%75 = call i32 @buf_read_until_newline(%struct.buf* %73, i32* %74)
%76 = load i32, i32* %9
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %69
%79 = load %struct.buf*, %struct.buf** %8
%80 = call i32 @buf_last(%struct.buf* %79)
store i32 %80, i32* %7
%81 = load %struct.buf*, %struct.buf** %8
%82 = call i32 @buf_strip(%struct.buf* %81)
br label %104
83: ; preds = %69
br label %13
84: ; preds = %66
%85 = load i32, i32* %7
%86 = icmp eq i32 %85, 125
br i1 %86, label %87, label %92
87: ; preds = %84
store i32 1, i32* %9
%88 = load i32*, i32** %6
store i32 1, i32* %88
%89 = load %struct.buf*, %struct.buf** %8
%90 = load i32, i32* %7
%91 = call i32 @buf_append(%struct.buf* %89, i32 %90)
br label %13
92: ; preds = %84
%93 = load i32, i32* %7
%94 = call i64 @isspace(i32 %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %99, label %96
96: ; preds = %92
%97 = load i32, i32* %7
%98 = icmp eq i32 %97, 59
br i1 %98, label %99, label %103
99: ; preds = %96, %92
%100 = load %struct.buf*, %struct.buf** %8
%101 = load i32, i32* %7
%102 = call i32 @buf_append(%struct.buf* %100, i32 %101)
br label %13
103: ; preds = %96
br label %104
104: ; preds = %103, %78, %61, %47, %33
%105 = load i32, i32* %7
%106 = load i32*, i32** %5
%107 = call i32 @ungetc_checked(i32 %105, i32* %106)
br label %108
108: ; preds = %104, %19
%109 = load %struct.buf*, %struct.buf** %8
%110 = call i32 @buf_finish(%struct.buf* %109)
%111 = load %struct.buf*, %struct.buf** %8
ret %struct.buf* %111
}

LLVM IR (-O2):
%struct.buf = type { i32 }
%struct.confctl = type { i32 }
@EOF = global i32 0
define %struct.buf* @buf_read_before(%struct.confctl* %0, i32* %1, i32* nocapture writeonly %2) {
store i32 0, i32* %2
%4 = tail call %struct.buf* (...) @buf_new()
%5 = tail call i32 @getc(i32* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %3, %31
%9 = phi i32 [ %33, %31 ], [ %5, %3 ]
%10 = phi i32 [ %32, %31 ], [ 0, %3 ]
%11 = icmp eq i32 %10, 0
br label %13
12: ; preds = %31, %24, %3
store i32 1, i32* %2
br label %53
13: ; preds = %8, %24
%14 = phi i32 [ %9, %8 ], [ %25, %24 ]
br i1 %11, label %16, label %15
15: ; preds = %13
switch i32 %14, label %40 [
i32 125, label %50
i32 13, label %50
i32 10, label %50
i32 47, label %17
i32 35, label %28
]
16: ; preds = %13
switch i32 %14, label %40 [
i32 47, label %17
i32 35, label %28
i32 125, label %38
]
17: ; preds = %15, %16
%18 = tail call i32 @buf_append(%struct.buf* %4, i32 47)
%19 = tail call i32 @buf_read_slashed(%struct.buf* %4, %struct.confctl* %0, i32* %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %47, label %21
21: ; preds = %17
br i1 %11, label %24, label %22
22: ; preds = %21
%23 = tail call i32 @buf_last(%struct.buf* %4)
switch i32 %23, label %24 [
i32 13, label %47
i32 10, label %47
]
24: ; preds = %21, %22, %45
%25 = tail call i32 @getc(i32* %1)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %12, label %13
28: ; preds = %15, %16
%29 = tail call i32 @buf_append(%struct.buf* %4, i32 35)
%30 = tail call i32 @buf_read_until_newline(%struct.buf* %4, i32* %1)
br i1 %11, label %31, label %36
31: ; preds = %28, %38
%32 = phi i32 [ 1, %38 ], [ 0, %28 ]
%33 = tail call i32 @getc(i32* %1)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %12, label %8
36: ; preds = %28
%37 = tail call i32 @buf_last(%struct.buf* %4)
br label %47
38: ; preds = %16
store i32 1, i32* %2
%39 = tail call i32 @buf_append(%struct.buf* %4, i32 125)
br label %31
40: ; preds = %15, %16
%41 = tail call i64 @isspace(i32 %14)
%42 = icmp ne i64 %41, 0
%43 = icmp eq i32 %14, 59
%44 = or i1 %43, %42
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = tail call i32 @buf_append(%struct.buf* %4, i32 %14)
br label %24
47: ; preds = %22, %22, %17, %36
%48 = phi i32 [ %37, %36 ], [ 47, %17 ], [ %23, %22 ], [ %23, %22 ]
%49 = tail call i32 @buf_strip(%struct.buf* %4)
br label %50
50: ; preds = %15, %15, %15, %40, %47
%51 = phi i32 [ %48, %47 ], [ %14, %40 ], [ %14, %15 ], [ %14, %15 ], [ %14, %15 ]
%52 = tail call i32 @ungetc_checked(i32 %51, i32* %1)
br label %53
53: ; preds = %50, %12
%54 = tail call i32 @buf_finish(%struct.buf* %4)
ret %struct.buf* %4
}