#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ rm_eo;
  int /*<<< orphan*/ rm_so;
};
typedef TYPE_1__ regmatch_t;

/* Variables and functions */
char *d_s(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rematch(char *, char *, size_t, TYPE_1__ *);
char *substring(char *, int /*<<< orphan*/, scalar_t__);
int main() {
  size_t nm = 2;
  regmatch_t pm[nm];
  char *s;
  printf("Enter string: ");
  s = d_s(s);
  char *re;
  printf("Enter regex with parenthesized subexpression: ");
  re = d_s(re);
  if (rematch(s, re, nm, pm))
    printf("Subexpression = [%s]\n",
           substring(s, pm[1].rm_so, pm[1].rm_eo - 1));
  else
    printf("Couldn't extract substring.\n");
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
shl    $0x4,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <d_s@plt>
mov    %rax,-0x28(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <d_s@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <rematch@plt>
cmp    $0x0,%rax
je     120d <main+0xbd>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    0x18(%rax),%esi
mov    0x10(%rax),%rdx
sub    $0x1,%rdx
call   1050 <substring@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121b <main+0xcb>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
call   1070 <d_s@plt>
mov    %rax,%rbx
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
call   1070 <d_s@plt>
mov    %rsp,%rcx
mov    $0x2,%edx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <rematch@plt>
test   %rax,%rax
je     11ce <main+0x6e>
mov    0x18(%rsp),%esi
mov    0x10(%rsp),%rdx
add    $0xffffffffffffffff,%rdx
mov    %rbx,%rdi
call   1060 <substring@plt>
lea    0xe7c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11da <main+0x7a>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32 }
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [47 x i8] c"Enter regex with parenthesized subexpression: \00"
@.str.2 = [22 x i8] c"Subexpression = [%s]\0A\00"
@.str.3 = [29 x i8] c"Couldn't extract substring.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i64 2, i64* %2
%7 = load i64, i64* %2
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca %struct.TYPE_3__, i64 %7
store i64 %7, i64* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %5
%12 = call i8* @d_s(i8* %11)
store i8* %12, i8** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %6
%15 = call i8* @d_s(i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i64, i64* %2
%19 = call i64 @rematch(i8* %16, i8* %17, i64 %18, %struct.TYPE_3__* %9)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %0
%22 = load i8*, i8** %5
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i64 1
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i64 1
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = sub nsw i64 %28, 1
%30 = call i8* @substring(i8* %22, i32 %25, i64 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = load i8*, i8** %5
%36 = call i32 @free(i8* %35)
store i32 0, i32* %1
%37 = load i8*, i8** %3
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32 }
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [47 x i8] c"Enter regex with parenthesized subexpression: \00"
@.str.2 = [22 x i8] c"Subexpression = [%s]\0A\00"
@str = [28 x i8] c"Couldn't extract substring.\00"
define i32 @main() {
%1 = alloca [2 x %struct.TYPE_3__]
%2 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @d_s(i8* undef)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @d_s(i8* undef)
%7 = call i64 @rematch(i8* %4, i8* %6, i64 2, %struct.TYPE_3__* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %0
%10 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %1, i64 0, i64 1, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %1, i64 0, i64 1, i32 0
%13 = load i64, i64* %12
%14 = add nsw i64 %13, -1
%15 = call i8* @substring(i8* %4, i32 %11, i64 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %9
%20 = call i32 @free(i8* %4)
ret i32 0
}