#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 int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
int /*<<< orphan*/ perrx(int, char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regmatch(char *, char *, int /*<<< orphan*/ *);
int checkgr(int argc, char *argv[], char *buf, int chkonly) {
  int i;
  regex_t re;
  for (i = 1; i <= argc; i++) {
    if (regcomp(&re, argv[i - 1], REG_EXTENDED | REG_NOSUB) != 0)
      (void)perrx(255, "Regex compilation failed");
    if (chkonly != 1)
      switch (regmatch(buf, argv[i - 1], &re)) {
      case 1:
        return i;
      case 0:
        if ((i + 1) <= argc)
          i++;
        break;
      }
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkgr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     122b <checkgr+0xfb>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11a0 <checkgr+0x70>
mov    $0xff,%edi
lea    0xe65(%rip),%rsi
call   1030 <perrx@plt>
cmpl   $0x1,-0x1c(%rbp)
je     1218 <checkgr+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <regmatch@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
test   %eax,%eax
je     11f6 <checkgr+0xc6>
jmp    11da <checkgr+0xaa>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
jne    1213 <checkgr+0xe3>
jmp    11eb <checkgr+0xbb>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1232 <checkgr+0x102>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jg     120e <checkgr+0xde>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1213 <checkgr+0xe3>
jmp    1218 <checkgr+0xe8>
jmp    121d <checkgr+0xed>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114d <checkgr+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkgr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
test   %edi,%edi
jle    11d4 <checkgr+0xa4>
mov    %ecx,%r15d
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%ebp
lea    0x14(%rsp),%r13
jmp    1176 <checkgr+0x46>
xor    %eax,%eax
cmp    %r12d,%ebp
setl   %al
add    %ebp,%eax
mov    %eax,%ebp
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jge    11d4 <checkgr+0xa4>
movslq %ebp,%r14
mov    -0x8(%rbx,%r14,8),%rsi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
or     (%rax),%edx
mov    %r13,%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
je     11ae <checkgr+0x7e>
mov    $0xff,%edi
lea    0xe57(%rip),%rsi
call   1030 <perrx@plt>
cmp    $0x1,%r15d
je     116c <checkgr+0x3c>
add    $0xffffffffffffffff,%r14
mov    (%rbx,%r14,8),%rsi
mov    0x8(%rsp),%rdi
mov    %r13,%rdx
call   1050 <regmatch@plt>
test   %eax,%eax
je     1160 <checkgr+0x30>
cmp    $0x1,%eax
jne    116c <checkgr+0x3c>
jmp    11d6 <checkgr+0xa6>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str = [25 x i8] c"Regex compilation failed\00"
define i32 @checkgr(i32 %0, i8** %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 1, i32* %10
br label %12
12: ; preds = %55, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %58
16: ; preds = %12
%17 = load i8**, i8*** %7
%18 = load i32, i32* %10
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %17, i64 %20
%22 = load i8*, i8** %21
%23 = load i32, i32* @REG_EXTENDED
%24 = load i32, i32* @REG_NOSUB
%25 = or i32 %23, %24
%26 = call i64 @regcomp(i32* %11, i8* %22, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @perrx(i32 255, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %54
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i8**, i8*** %7
%36 = load i32, i32* %10
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %35, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @regmatch(i8* %34, i8* %40, i32* %11)
switch i32 %41, label %53 [
i32 1, label %42
i32 0, label %44
]
42: ; preds = %33
%43 = load i32, i32* %10
store i32 %43, i32* %5
br label %59
44: ; preds = %33
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %6
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %52
52: ; preds = %49, %44
br label %53
53: ; preds = %33, %52
br label %54
54: ; preds = %53, %30
br label %55
55: ; preds = %54
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %12
58: ; preds = %12
store i32 0, i32* %5
br label %59
59: ; preds = %58, %42
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str = [25 x i8] c"Regex compilation failed\00"
define i32 @checkgr(i32 %0, i8** nocapture %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp slt i32 %0, 1
br i1 %7, label %35, label %8
8: ; preds = %4
%9 = icmp eq i32 %3, 1
br label %10
10: ; preds = %8, %31
%11 = phi i32 [ 1, %8 ], [ %33, %31 ]
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = load i32, i32* @REG_EXTENDED
%17 = load i32, i32* @REG_NOSUB
%18 = or i32 %17, %16
%19 = call i64 @regcomp(i32* %5, i8* %15, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %10
%22 = call i32 @perrx(i32 255, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
br i1 %9, label %31, label %24
24: ; preds = %23
%25 = load i8*, i8** %14
%26 = call i32 @regmatch(i8* %2, i8* %25, i32* %5)
switch i32 %26, label %31 [
i32 1, label %35
i32 0, label %27
]
27: ; preds = %24
%28 = icmp slt i32 %11, %0
%29 = zext i1 %28 to i32
%30 = add nsw i32 %11, %29
br label %31
31: ; preds = %27, %23, %24
%32 = phi i32 [ %11, %24 ], [ %11, %23 ], [ %30, %27 ]
%33 = add nsw i32 %32, 1
%34 = icmp slt i32 %32, %0
br i1 %34, label %10, label %35
35: ; preds = %24, %31, %4
%36 = phi i32 [ 0, %4 ], [ 0, %31 ], [ %11, %24 ]
ret i32 %36
}