#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 */
typedef struct TYPE_9__ TYPE_2__;
typedef struct TYPE_8__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  int /*<<< orphan*/ rm_so;
};
typedef TYPE_1__ regmatch_t;
struct TYPE_9__ {
  scalar_t__ re_nsub;
};
typedef TYPE_2__ regex_t;

/* Variables and functions */
#define REG_NOMATCH 128
int /*<<< orphan*/ exit_regerror(int, TYPE_2__ *);
int /*<<< orphan*/ pbnum(int);
int /*<<< orphan*/ pbunsigned(int /*<<< orphan*/);
int regexec(TYPE_2__ *, char const *, scalar_t__, TYPE_1__ *,
            int /*<<< orphan*/);
void do_regexpindex(const char *string, regex_t *re, regmatch_t *pm) {
  int error;
  switch (error = regexec(re, string, re->re_nsub + 1, pm, 0)) {
  case 0:
    pbunsigned(pm[0].rm_so);
    break;
  case REG_NOMATCH:
    pbnum(-1);
    break;
  default:
    exit_regerror(error, re);
  }
}


x86 assembly (clang, -O0):
<do_regexpindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    (%rdi),%rdx
add    $0x1,%rdx
mov    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
test   %eax,%eax
je     1197 <do_regexpindex+0x57>
jmp    1184 <do_regexpindex+0x44>
mov    -0x20(%rbp),%eax
sub    $0x80,%eax
je     11a7 <do_regexpindex+0x67>
jmp    11b6 <do_regexpindex+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <pbunsigned@plt>
jmp    11c2 <do_regexpindex+0x82>
mov    $0xffffffff,%edi
call   1040 <pbnum@plt>
jmp    11c2 <do_regexpindex+0x82>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <exit_regerror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_regexpindex>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    (%rbx),%rdx
add    $0x1,%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
cmp    $0x80,%eax
je     117c <do_regexpindex+0x3c>
test   %eax,%eax
jne    118d <do_regexpindex+0x4d>
mov    (%r14),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <pbunsigned@plt>
mov    $0xffffffff,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <pbnum@plt>
mov    %eax,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <exit_regerror@plt>

LLVM IR (-O0):
%struct.TYPE_9__ = type { i64 }
%struct.TYPE_8__ = type { i32 }
define void @do_regexpindex(i8* %0, %struct.TYPE_9__* %1, %struct.TYPE_8__* %2) {
%4 = alloca i8*
%5 = alloca %struct.TYPE_9__*
%6 = alloca %struct.TYPE_8__*
%7 = alloca i32
store i8* %0, i8** %4
store %struct.TYPE_9__* %1, %struct.TYPE_9__** %5
store %struct.TYPE_8__* %2, %struct.TYPE_8__** %6
%8 = load %struct.TYPE_9__*, %struct.TYPE_9__** %5
%9 = load i8*, i8** %4
%10 = load %struct.TYPE_9__*, %struct.TYPE_9__** %5
%11 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = add nsw i64 %12, 1
%14 = load %struct.TYPE_8__*, %struct.TYPE_8__** %6
%15 = call i32 @regexec(%struct.TYPE_9__* %8, i8* %9, i64 %13, %struct.TYPE_8__* %14, i32 0)
store i32 %15, i32* %7
switch i32 %15, label %24 [
i32 0, label %16
i32 128, label %22
]
16: ; preds = %3
%17 = load %struct.TYPE_8__*, %struct.TYPE_8__** %6
%18 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %17, i64 0
%19 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @pbunsigned(i32 %20)
br label %28
22: ; preds = %3
%23 = call i32 @pbnum(i32 -1)
br label %28
24: ; preds = %3
%25 = load i32, i32* %7
%26 = load %struct.TYPE_9__*, %struct.TYPE_9__** %5
%27 = call i32 @exit_regerror(i32 %25, %struct.TYPE_9__* %26)
br label %28
28: ; preds = %24, %22, %16
ret void
}

LLVM IR (-O2):
%struct.TYPE_9__ = type { i64 }
%struct.TYPE_8__ = type { i32 }
define void @do_regexpindex(i8* %0, %struct.TYPE_9__* %1, %struct.TYPE_8__* %2) {
%4 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = add nsw i64 %5, 1
%7 = tail call i32 @regexec(%struct.TYPE_9__* %1, i8* %0, i64 %6, %struct.TYPE_8__* %2, i32 0)
switch i32 %7, label %14 [
i32 0, label %8
i32 128, label %12
]
8: ; preds = %3
%9 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @pbunsigned(i32 %10)
br label %16
12: ; preds = %3
%13 = tail call i32 @pbnum(i32 -1)
br label %16
14: ; preds = %3
%15 = tail call i32 @exit_regerror(i32 %7, %struct.TYPE_9__* %1)
br label %16
16: ; preds = %14, %12, %8
ret void
}