#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int get_next_reaction(char **str_start_inout, char *reac) {
  char *str_dblquote_start;
  char *str_dblquote_stop;
  char *str_start;
  str_start = *str_start_inout;
  str_dblquote_start = strstr(str_start, "\"");
  if (str_dblquote_start == NULL) {
    return (-1);
  }
  str_dblquote_stop = strstr(str_dblquote_start + 1, "\"");
  if (str_dblquote_stop == NULL) {
    printf(
        "FATAL ERROR: invalid syntax in reaction file: missing double quote\n");
    exit(EXIT_FAILURE);
  }
  if (str_dblquote_stop == str_dblquote_start + 1) {
    printf("FATAL ERROR: invalid syntax in reaction file: reaction name with "
           "length 0\n");
    exit(EXIT_FAILURE);
  }
  strncpy(reac, str_dblquote_start + 1,
          str_dblquote_stop - str_dblquote_start - 1);
  reac[str_dblquote_stop - str_dblquote_start - 1] = '\0';
  *str_start_inout = str_dblquote_stop + 1;
  return (0);
}


x86 assembly (clang, -O0):
<get_next_reaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <get_next_reaction+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <get_next_reaction+0x101>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe6b(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <get_next_reaction+0x83>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11f2 <get_next_reaction+0xb2>
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_reaction>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a5 <get_next_reaction+0x65>
mov    %rax,%rbx
lea    0x1(%rax),%r12
mov    %r12,%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b4 <get_next_reaction+0x74>
mov    %rax,%r13
cmp    %r12,%rax
je     11bd <get_next_reaction+0x7d>
not    %rbx
add    %r13,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
add    $0x1,%r13
mov    %r13,(%r15)
xor    %eax,%eax
jmp    11aa <get_next_reaction+0x6a>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe8f(%rip),%rdi
jmp    11c4 <get_next_reaction+0x84>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [68 x i8] c"FATAL ERROR: invalid syntax in reaction file: missing double quote\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [75 x i8] c"FATAL ERROR: invalid syntax in reaction file: reaction name with length 0\0A\00"
define i32 @get_next_reaction(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %58
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = icmp eq i8* %27, %29
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = load i8*, i8** %5
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8*, i8** %7
%40 = load i8*, i8** %6
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = sub nsw i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i32 @strncpy(i8* %36, i8* %38, i32 %45)
%47 = load i8*, i8** %5
%48 = load i8*, i8** %7
%49 = load i8*, i8** %6
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = sub nsw i64 %52, 1
%54 = getelementptr inbounds i8, i8* %47, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8**, i8*** %4
store i8* %56, i8** %57
store i32 0, i32* %3
br label %58
58: ; preds = %35, %15
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [74 x i8] c"FATAL ERROR: invalid syntax in reaction file: reaction name with length 0\00"
@str.3 = [67 x i8] c"FATAL ERROR: invalid syntax in reaction file: missing double quote\00"
define i32 @get_next_reaction(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %3, i32 34)
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i8* @strchr(i8* %7, i32 34)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.3, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6
%15 = icmp eq i8* %8, %7
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %14
%21 = ptrtoint i8* %8 to i64
%22 = ptrtoint i8* %4 to i64
%23 = xor i64 %22, -1
%24 = add i64 %21, %23
%25 = trunc i64 %24 to i32
%26 = tail call i32 @strncpy(i8* %1, i8* %7, i32 %25)
%27 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %27
%28 = getelementptr inbounds i8, i8* %8, i64 1
store i8* %28, i8** %0
br label %29
29: ; preds = %2, %20
%30 = phi i32 [ 0, %20 ], [ -1, %2 ]
ret i32 %30
}