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

/* Variables and functions */
int REG_NOMATCH;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ puts(char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main() {
  regex_t re;
  int re_err;
  char s[100] = "abc";
  if ((re_err = (regcomp(&re, "b", 0)))) {
    fprintf(stderr, "Could not compile regex\n");
    exit(1);
  }
  if (!(re_err = (regexec(&re, s, 0, NULL, 0))))
    puts("Match");
  else if (re_err == REG_NOMATCH)
    puts("No match");
  else {
    regerror(re_err, &re, s, sizeof(s));
    fprintf(stderr, "Regex match failed: %s\n", s);
    exit(1);
  }
  regfree(&re);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
movb   $0x61,-0x70(%rbp)
movb   $0x62,-0x6f(%rbp)
movb   $0x63,-0x6e(%rbp)
lea    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
xor    %edx,%edx
call   1060 <regcomp@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     11ea <main+0x6a>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rsi
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1090 <regexec@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    121e <main+0x9e>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
jmp    1280 <main+0x100>
mov    -0xc(%rbp),%eax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
jne    1241 <main+0xc1>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
jmp    127b <main+0xfb>
mov    -0xc(%rbp),%edi
lea    -0x70(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0x64,%ecx
call   1080 <regerror@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1280 <main+0x100>
lea    -0x8(%rbp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x70(%rsp)
movw   $0x6261,0x10(%rsp)
movb   $0x63,0x12(%rsp)
lea    0xe4c(%rip),%rsi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
call   1050 <regcomp@plt>
test   %eax,%eax
jne    1213 <main+0xa3>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11f2 <main+0x82>
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%eax
jne    1234 <main+0xc4>
lea    0xe31(%rip),%rdi
jmp    11f9 <main+0x89>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1070 <regerror@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"b\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.3 = [9 x i8] c"No match\00"
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = bitcast [100 x i8]* %4 to i8*
%6 = bitcast i8* %5 to [100 x i8]*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 0
store i8 97, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 1
store i8 98, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 2
store i8 99, i8* %9
%10 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = call i32 @regexec(i32* %2, i8* %17, i32 0, i32* null, i32 0)
store i32 %18, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %37
22: ; preds = %16
%23 = load i32, i32* %3
%24 = load i32, i32* @REG_NOMATCH
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %36
28: ; preds = %22
%29 = load i32, i32* %3
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = call i32 @regerror(i32 %29, i32* %2, i8* %30, i32 100)
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
br label %37
37: ; preds = %36, %20
%38 = call i32 @regfree(i32* %2)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"b\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.3 = [9 x i8] c"No match\00"
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8 97, i8* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
store i8 98, i8* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
store i8 99, i8* %6
%7 = call i32 @regcomp(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @regexec(i32* %1, i8* %4, i32 0, i32* null, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = load i32, i32* @REG_NOMATCH
%18 = icmp eq i32 %14, %17
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = call i32 @regerror(i32 %14, i32* %1, i8* %4, i32 100)
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16, %13
%25 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %16 ]
%26 = call i32 @puts(i8* dereferenceable(1) %25)
%27 = call i32 @regfree(i32* %1)
ret i32 0
}