#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__ {
  int rm_so;
  int rm_eo;
};
typedef TYPE_1__ regmatch_t;

/* Variables and functions */
char *strncpy(char *, char *, int);
char *substringRegex(char *src, char *dest, regmatch_t *match) {
  char *offsetString = src + match[0].rm_so;
  int length = match[0].rm_eo - match[0].rm_so;
  dest = strncpy(dest, offsetString, length);
  dest[length] = '\0';
  return dest;
}


x86 assembly (clang, -O0):
<substringRegex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substringRegex>:
push   %rbx
mov    %rsi,%rax
movslq (%rdx),%rcx
lea    (%rdi,%rcx,1),%rsi
movslq 0x4(%rdx),%rbx
sub    %rcx,%rbx
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rax,%rbx,1)
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define i8* @substringRegex(i8* %0, i8* %1, %struct.TYPE_3__* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.TYPE_3__*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.TYPE_3__* %2, %struct.TYPE_3__** %6
%9 = load i8*, i8** %4
%10 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i64 0
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
store i8* %15, i8** %7
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i64 0
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i64 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %19, %23
store i32 %24, i32* %8
%25 = load i8*, i8** %5
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i8* @strncpy(i8* %25, i8* %26, i32 %27)
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i8* @substringRegex(i8* %0, i8* %1, %struct.TYPE_3__* nocapture %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
%5 = load i32, i32* %4
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%9 = load i32, i32* %8
%10 = sub nsw i32 %9, %5
%11 = tail call i8* @strncpy(i8* %1, i8* %7, i32 %10)
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8 0, i8* %13
ret i8* %11
}