#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ normalize_space(char *);
int /*<<< orphan*/ print_item(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strspn(char *, char *);
char *strstr(char *, char *);
int parse_record(char *buf, int html) {
  char *p, key[32];
  buf += strspn(buf, " ");
  if (strncmp(buf, "\\bibitem", 8)) {
    return 0;
  }
  normalize_space(buf);
  p = strchr(buf, ']');
  if (p == NULL) {
    fprintf(stderr, "*** Couldn't find closing ']'\n");
    return 1;
  }
  p++;
  buf = p;
  while (*p) {
    if (*p == '~') {
      *p = ' ';
    }
    p++;
  }
  buf += strspn(buf, " ");
  if (*buf == '{') {
    int n;
    p = strchr(buf, '}');
    n = p - buf - 1;
    if (n >= 32) {
      fprintf(stderr, "*** bib key is too long (%d > 31)\n", n);
      return 1;
    } else {
      *key = '\0';
      strncat(key, buf + 1, n);
      buf = p + 1;
    }
  }
  buf += strspn(buf, " ");
  p = strstr(buf, "Reprinted");
  if (p != NULL) {
    *p = '\0';
  }
  print_item(buf, key, html);
  return 0;
}


x86 assembly (clang, -O0):
<parse_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11da <parse_record+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1376 <parse_record+0x1f6>
mov    -0x10(%rbp),%rdi
call   1080 <normalize_space@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1223 <parse_record+0xa3>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1376 <parse_record+0x1f6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     126c <parse_record+0xec>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    125b <parse_record+0xdb>
mov    -0x20(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1237 <parse_record+0xb7>
mov    -0x10(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   1060 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    1319 <parse_record+0x199>
mov    -0x10(%rbp),%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x44(%rbp)
cmpl   $0x20,-0x44(%rbp)
jl     12f0 <parse_record+0x170>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1376 <parse_record+0x1f6>
movb   $0x0,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x44(%rbp),%edx
call   1050 <strncat@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1319 <parse_record+0x199>
mov    -0x10(%rbp),%rdi
lea    0xcdc(%rip),%rsi
call   1060 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd09(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     135f <parse_record+0x1df>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <print_item@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_record>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe69(%rip),%rsi
call   1060 <strspn@plt>
movslq %eax,%rbx
add    %rbp,%rbx
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    12cc <parse_record+0x14c>
mov    %rbx,%rdi
call   1080 <normalize_space@plt>
mov    %rbx,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1259 <parse_record+0xd9>
mov    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rax
jmp    11f7 <parse_record+0x77>
nopl   0x0(%rax)
movb   $0x20,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x7e,%cl
je     11f0 <parse_record+0x70>
test   %cl,%cl
jne    11f3 <parse_record+0x73>
lea    0xdf6(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strspn@plt>
cltq
lea    (%rax,%rbp,1),%rbx
cmpb   $0x7b,0x0(%rbp,%rax,1)
jne    1292 <parse_record+0x112>
mov    %rbx,%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
mov    %ebx,%edx
not    %edx
add    %ebp,%edx
cmp    $0x20,%edx
jl     1278 <parse_record+0xf8>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%r15d
jmp    12cc <parse_record+0x14c>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%r15d
jmp    12cc <parse_record+0x14c>
movb   $0x0,(%rsp)
add    $0x1,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <strncat@plt>
add    $0x1,%rbp
mov    %rbp,%rbx
lea    0xd67(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strspn@plt>
movslq %eax,%rbp
add    %rbx,%rbp
lea    0xd9f(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     12be <parse_record+0x13e>
movb   $0x0,(%rax)
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1070 <print_item@plt>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [9 x i8] c"\\bibitem\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"*** Couldn't find closing ']'\0A\00"
@.str.3 = [35 x i8] c"*** bib key is too long (%d > 31)\0A\00"
@.str.4 = [10 x i8] c"Reprinted\00"
define i32 @parse_record(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [32 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @strspn(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %4
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %99
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @normalize_space(i8* %19)
%21 = load i8*, i8** %4
%22 = call i8* @strchr(i8* %21, i8 signext 93)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %99
28: ; preds = %18
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
%31 = load i8*, i8** %6
store i8* %31, i8** %4
br label %32
32: ; preds = %43, %28
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 126
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i8*, i8** %6
store i8 32, i8* %42
br label %43
43: ; preds = %41, %36
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %6
br label %32
46: ; preds = %32
%47 = load i8*, i8** %4
%48 = call i32 @strspn(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%49 = load i8*, i8** %4
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8* %51, i8** %4
%52 = load i8*, i8** %4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 123
br i1 %55, label %56, label %82
56: ; preds = %46
%57 = load i8*, i8** %4
%58 = call i8* @strchr(i8* %57, i8 signext 125)
store i8* %58, i8** %6
%59 = load i8*, i8** %6
%60 = load i8*, i8** %4
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = sub nsw i64 %63, 1
%65 = trunc i64 %64 to i32
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp sge i32 %66, 32
br i1 %67, label %68, label %72
68: ; preds = %56
%69 = load i32, i32* @stderr
%70 = load i32, i32* %8
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %70)
store i32 1, i32* %3
br label %99
72: ; preds = %56
%73 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
store i8 0, i8* %73
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%75 = load i8*, i8** %4
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = load i32, i32* %8
%78 = call i32 @strncat(i8* %74, i8* %76, i32 %77)
%79 = load i8*, i8** %6
%80 = getelementptr inbounds i8, i8* %79, i64 1
store i8* %80, i8** %4
br label %81
81: ; preds = %72
br label %82
82: ; preds = %81, %46
%83 = load i8*, i8** %4
%84 = call i32 @strspn(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%85 = load i8*, i8** %4
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8, i8* %85, i64 %86
store i8* %87, i8** %4
%88 = load i8*, i8** %4
%89 = call i8* @strstr(i8* %88, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i8* %89, i8** %6
%90 = load i8*, i8** %6
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %94
92: ; preds = %82
%93 = load i8*, i8** %6
store i8 0, i8* %93
br label %94
94: ; preds = %92, %82
%95 = load i8*, i8** %4
%96 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%97 = load i32, i32* %5
%98 = call i32 @print_item(i8* %95, i8* %96, i32 %97)
store i32 0, i32* %3
br label %99
99: ; preds = %94, %68, %25, %17
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [9 x i8] c"\\bibitem\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"*** Couldn't find closing ']'\0A\00"
@.str.3 = [35 x i8] c"*** bib key is too long (%d > 31)\0A\00"
@.str.4 = [10 x i8] c"Reprinted\00"
define i32 @parse_record(i8* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %56
10: ; preds = %2
%11 = tail call i32 @normalize_space(i8* %7)
%12 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 93)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %56
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %12, i64 1
br label %19
19: ; preds = %23, %17
%20 = phi i8* [ %18, %17 ], [ %24, %23 ]
%21 = load i8, i8* %20
switch i8 %21, label %23 [
i8 0, label %25
i8 126, label %22
]
22: ; preds = %19
store i8 32, i8* %20
br label %23
23: ; preds = %19, %22
%24 = getelementptr inbounds i8, i8* %20, i64 1
br label %19
25: ; preds = %19
%26 = tail call i32 @strspn(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %18, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 123
br i1 %30, label %31, label %46
31: ; preds = %25
%32 = tail call i8* @strchr(i8* %28, i8 signext 125)
%33 = ptrtoint i8* %32 to i64
%34 = ptrtoint i8* %28 to i64
%35 = xor i64 %34, -1
%36 = add i64 %33, %35
%37 = trunc i64 %36 to i32
%38 = icmp sgt i32 %37, 31
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %56
42: ; preds = %31
store i8 0, i8* %4
%43 = getelementptr inbounds i8, i8* %28, i64 1
%44 = call i32 @strncat(i8* %4, i8* %43, i32 %37)
%45 = getelementptr inbounds i8, i8* %32, i64 1
br label %46
46: ; preds = %42, %25
%47 = phi i8* [ %45, %42 ], [ %28, %25 ]
%48 = call i32 @strspn(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = call i8* @strstr(i8* dereferenceable(1) %50, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i8* %51, null
br i1 %52, label %54, label %53
53: ; preds = %46
store i8 0, i8* %51
br label %54
54: ; preds = %53, %46
%55 = call i32 @print_item(i8* %50, i8* %4, i32 %1)
br label %56
56: ; preds = %39, %2, %54, %14
%57 = phi i32 [ 1, %14 ], [ 0, %54 ], [ 0, %2 ], [ 1, %39 ]
ret i32 %57
}