#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_eo;
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int /*<<< orphan*/ perror(char *);
int read_config_file(char **, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int get_logdir_from_config(char **ret_logdir, char *path_prefix) {
  int file_size;
  char *txt;
  regex_t preg;
  int err;
  char errmsg[1000];
  regmatch_t matches[3];
  char *logdir;
  int sz;
  char regex[] =
      "^(//){0}.*\\$TSUNG_CONFIG\\['log_dir'\\][ \t\n]*=[ \t\n]*\"([^\"]*)\"";
  file_size = read_config_file(&txt, path_prefix);
  err = regcomp(&preg, &(regex[0]), REG_EXTENDED);
  if (err) {
    regerror(err, &preg, &(errmsg[0]), 1000);
    fprintf(stderr, "Regex error: %s\n", errmsg);
    regfree(&preg);
    free(txt);
    exit(-1);
  }
  if (regexec(&preg, txt, 3, matches, 0)) {
    fprintf(stderr, "Couldn't find $TSUNG_CONFIG['log_dir']\n");
    fprintf(stderr, "File:%s\n", txt);
    fprintf(stderr, "Regex: (%s)\n", regex);
    regfree(&preg);
    free(txt);
    exit(-1);
  }
  sz = matches[2].rm_eo - matches[2].rm_so;
  logdir = (char *)malloc(sizeof(char) * (sz + 1));
  if (!logdir) {
    perror("Could not allocate memory for logdir string.");
    regfree(&preg);
    free(txt);
    exit(-1);
  }
  memcpy((void *)logdir, (void *)(txt + matches[2].rm_so), sz);
  logdir[sz] = '\0';
  regfree(&preg);
  free(txt);
  *ret_logdir = logdir;
  return sz;
}


x86 assembly (clang, -O0):
<get_logdir_from_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x480(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x3c,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   10a0 <read_config_file@plt>
mov    %eax,-0x14(%rbp)
lea    -0x480(%rbp),%rsi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1263 <get_logdir_from_config+0xb3>
mov    -0x28(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    -0x24(%rbp),%rsi
mov    $0x3e8,%ecx
call   1080 <regerror@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x24(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    -0x430(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x3,%edx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
cmp    $0x0,%rax
je     12f5 <get_logdir_from_config+0x145>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    -0x480(%rbp),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x24(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x420(%rbp),%eax
sub    -0x41c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    135a <get_logdir_from_config+0x1aa>
lea    0xd52(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x24(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x438(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x41c(%rbp),%rax
add    %rax,%rsi
mov    -0x43c(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x438(%rbp),%rax
movslq -0x43c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x24(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x438(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x43c(%rbp),%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_logdir_from_config>:
push   %r15
push   %r14
push   %rbx
sub    $0x440,%rsp
mov    %rdi,%r14
movups 0xe66(%rip),%xmm0
movups %xmm0,0x3c(%rsp)
movaps 0xe4e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe32(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe16(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   10a0 <read_config_file@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <regcomp@plt>
test   %eax,%eax
jne    129e <get_logdir_from_config+0xee>
mov    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdi
lea    0x50(%rsp),%rcx
mov    $0x3,%edx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %rax,%rax
jne    12d9 <get_logdir_from_config+0x129>
movslq 0x60(%rsp),%rbx
movslq 0x64(%rsp),%rax
sub    %rax,%rbx
lea    0x1(%rbx),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     131c <get_logdir_from_config+0x16c>
mov    %rax,%r15
movslq 0x64(%rsp),%rsi
add    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1070 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
lea    0x4(%rsp),%rdi
call   1040 <regfree@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,(%r14)
mov    %ebx,%eax
add    $0x440,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x4(%rsp),%r14
lea    0x50(%rsp),%rbx
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x3e8,%ecx
call   1080 <regerror@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
jmp    132d <get_logdir_from_config+0x17d>
mov    0x2d00(%rip),%rbx
mov    (%rbx),%edi
lea    0xd64(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x8(%rsp),%rdx
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd70(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1328 <get_logdir_from_config+0x178>
lea    0xd68(%rip),%rdi
call   10c0 <perror@plt>
lea    0x4(%rsp),%rdi
call   1040 <regfree@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@__const.get_logdir_from_config.regex = [60 x i8] c"^(//){0}.*\\$TSUNG_CONFIG\\['log_dir'\\][ \09\0A]*=[ \09\0A]*\22([^\22]*)\22\00"
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Regex error: %s\0A\00"
@.str.1 = [40 x i8] c"Couldn't find $TSUNG_CONFIG['log_dir']\0A\00"
@.str.2 = [9 x i8] c"File:%s\0A\00"
@.str.3 = [13 x i8] c"Regex: (%s)\0A\00"
@.str.4 = [45 x i8] c"Could not allocate memory for logdir string.\00"
define i32 @get_logdir_from_config(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1000 x i8]
%10 = alloca [3 x %struct.TYPE_3__]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [60 x i8]
store i8** %0, i8*** %3
store i8* %1, i8** %4
%14 = bitcast [60 x i8]* %13 to i8*
%15 = load i8*, i8** %4
%16 = call i32 @read_config_file(i8** %6, i8* %15)
store i32 %16, i32* %5
%17 = getelementptr inbounds [60 x i8], [60 x i8]* %13, i64 0, i64 0
%18 = load i32, i32* @REG_EXTENDED
%19 = call i32 @regcomp(i32* %7, i8* %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %2
%23 = load i32, i32* %8
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%25 = call i32 @regerror(i32 %23, i32* %7, i8* %24, i32 1000)
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @regfree(i32* %7)
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %2
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %10, i64 0, i64 0
%36 = call i64 @regexec(i32* %7, i8* %34, i32 3, %struct.TYPE_3__* %35, i32 0)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %51
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %6
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [60 x i8], [60 x i8]* %13, i64 0, i64 0
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = call i32 @regfree(i32* %7)
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %33
%52 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %10, i64 0, i64 2
%53 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %10, i64 0, i64 2
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 1
%57 = load i32, i32* %56
%58 = sub nsw i32 %54, %57
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = add nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = mul i64 1, %61
%63 = trunc i64 %62 to i32
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %11
%66 = load i8*, i8** %11
%67 = icmp ne i8* %66, null
br i1 %67, label %74, label %68
68: ; preds = %51
%69 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 @regfree(i32* %7)
%71 = load i8*, i8** %6
%72 = call i32 @free(i8* %71)
%73 = call i32 @exit(i32 -1)
unreachable
74: ; preds = %51
%75 = load i8*, i8** %11
%76 = load i8*, i8** %6
%77 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %10, i64 0, i64 2
%78 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %76, i64 %80
%82 = load i32, i32* %12
%83 = call i32 @memcpy(i8* %75, i8* %81, i32 %82)
%84 = load i8*, i8** %11
%85 = load i32, i32* %12
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
store i8 0, i8* %87
%88 = call i32 @regfree(i32* %7)
%89 = load i8*, i8** %6
%90 = call i32 @free(i8* %89)
%91 = load i8*, i8** %11
%92 = load i8**, i8*** %3
store i8* %91, i8** %92
%93 = load i32, i32* %12
ret i32 %93
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@__const.get_logdir_from_config.regex = [60 x i8] c"^(//){0}.*\\$TSUNG_CONFIG\\['log_dir'\\][ \09\0A]*=[ \09\0A]*\22([^\22]*)\22\00"
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Regex error: %s\0A\00"
@.str.1 = [40 x i8] c"Couldn't find $TSUNG_CONFIG['log_dir']\0A\00"
@.str.2 = [9 x i8] c"File:%s\0A\00"
@.str.3 = [13 x i8] c"Regex: (%s)\0A\00"
@.str.4 = [45 x i8] c"Could not allocate memory for logdir string.\00"
define i32 @get_logdir_from_config(i8** nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca [3 x %struct.TYPE_3__]
%7 = alloca [60 x i8]
%8 = bitcast i8** %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%11 = bitcast [3 x %struct.TYPE_3__]* %6 to i8*
%12 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%13 = call i32 @read_config_file(i8** %3, i8* %1)
%14 = load i32, i32* @REG_EXTENDED
%15 = call i32 @regcomp(i32* %4, i8* %12, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %2
%18 = call i32 @regerror(i32 %15, i32* %4, i8* %10, i32 1000)
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%21 = call i32 @regfree(i32* %4)
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %2
%26 = load i8*, i8** %3
%27 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 0
%28 = call i64 @regexec(i32* %4, i8* %26, i32 3, %struct.TYPE_3__* %27, i32 0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %3
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%38 = call i32 @regfree(i32* %4)
%39 = load i8*, i8** %3
%40 = call i32 @free(i8* %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %25
%43 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 2, i32 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 2, i32 1
%46 = load i32, i32* %45
%47 = sub nsw i32 %44, %46
%48 = add nsw i32 %47, 1
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
%51 = icmp eq i64 %49, 0
br i1 %51, label %52, label %58
52: ; preds = %42
%53 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @regfree(i32* %4)
%55 = load i8*, i8** %3
%56 = call i32 @free(i8* %55)
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %42
%59 = load i8*, i8** %3
%60 = load i32, i32* %45
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = call i32 @memcpy(i8* %50, i8* %62, i32 %47)
%64 = sext i32 %47 to i64
%65 = getelementptr inbounds i8, i8* %50, i64 %64
store i8 0, i8* %65
%66 = call i32 @regfree(i32* %4)
%67 = load i8*, i8** %3
%68 = call i32 @free(i8* %67)
store i8* %50, i8** %0
ret i32 %47
}