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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
scalar_t__ REG_NOMATCH;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int parse_systemid_path(char *systemid_path, int systemid_path_length) {
  int ret = 1;
  FILE *config_file;
  regex_t re_systemIdPath;
  regmatch_t submatch[2];
  const char *regex =
      "^[[:space:]]*systemIdPath[[:space:]]*=[[:space:]]*([[:print:]]+)";
  if (regcomp(&re_systemIdPath, regex, REG_EXTENDED) != 0)
    return ret;
  if (NULL != (config_file = fopen("/etc/sysconfig/rhn/up2date", "r"))) {
    char line[(2 * 512)];
    while (NULL != fgets(line, (2 * 512), config_file)) {
      if (regexec(&re_systemIdPath, line, 2, submatch, 0) != REG_NOMATCH) {
        int match_length = submatch[1].rm_eo - submatch[1].rm_so;
        if (systemid_path_length < match_length)
          match_length = systemid_path_length - 1;
        strncpy(systemid_path, &line[submatch[1].rm_so], match_length);
        systemid_path[match_length] = '\0';
        ret = 0;
        break;
      }
    }
    fclose(config_file);
  }
  regfree(&re_systemIdPath);
  return ret;
}


x86 assembly (clang, -O0):
<parse_systemid_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1060 <regcomp@plt>
cmp    $0x0,%rax
je     11bf <parse_systemid_path+0x4f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <parse_systemid_path+0x143>
lea    0xe7b(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     12a4 <parse_systemid_path+0x134>
jmp    11e9 <parse_systemid_path+0x79>
lea    -0x460(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     129b <parse_systemid_path+0x12b>
lea    -0x460(%rbp),%rsi
lea    -0x50(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x2,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <parse_systemid_path+0x126>
movslq -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,-0x464(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x464(%rbp),%eax
jge    1261 <parse_systemid_path+0xf1>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x464(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x460(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x464(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x464(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x18(%rbp)
jmp    129b <parse_systemid_path+0x12b>
jmp    11e9 <parse_systemid_path+0x79>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x24(%rbp),%rdi
call   1050 <regfree@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_systemid_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
lea    0xe69(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1060 <regcomp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1276 <parse_systemid_path+0x106>
lea    0xe8b(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1258 <parse_systemid_path+0xe8>
mov    %rax,%r12
mov    %rbp,0x8(%rsp)
lea    0x30(%rsp),%rbx
lea    0x4(%rsp),%r13
lea    0x10(%rsp),%rbp
mov    0x2dff(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125f <parse_systemid_path+0xef>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    (%r14),%rax
je     11f0 <parse_systemid_path+0x80>
mov    0x20(%rsp),%eax
mov    0x28(%rsp),%rcx
sub    %ecx,%eax
lea    -0x1(%r15),%ebx
cmp    %r15d,%eax
cmovle %eax,%ebx
lea    (%rsp,%rcx,1),%rsi
add    $0x30,%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x0(%rbp,%rax,1)
xor    %ebx,%ebx
jmp    1264 <parse_systemid_path+0xf4>
mov    $0x1,%ebx
jmp    126c <parse_systemid_path+0xfc>
mov    $0x1,%ebx
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0x4(%rsp),%rdi
call   1050 <regfree@plt>
mov    %ebx,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64 }
@.str = [65 x i8] c"^[[:space:]]*systemIdPath[[:space:]]*=[[:space:]]*([[:print:]]+)\00"
@REG_EXTENDED = global i32 0
@.str.1 = [27 x i8] c"/etc/sysconfig/rhn/up2date\00"
@.str.2 = [2 x i8] c"r\00"
@REG_NOMATCH = global i64 0
define i32 @parse_systemid_path(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [2 x %struct.TYPE_3__]
%10 = alloca i8*
%11 = alloca [1024 x i8]
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %6
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8** %10
%13 = load i8*, i8** %10
%14 = load i32, i32* @REG_EXTENDED
%15 = call i64 @regcomp(i32* %8, i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %69
19: ; preds = %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %7
%21 = icmp ne i32* null, %20
br i1 %21, label %22, label %66
22: ; preds = %19
br label %23
23: ; preds = %62, %22
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = call i32* @fgets(i8* %24, i32 1024, i32* %25)
%27 = icmp ne i32* null, %26
br i1 %27, label %28, label %63
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%30 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %9, i64 0, i64 0
%31 = call i64 @regexec(i32* %8, i8* %29, i32 2, %struct.TYPE_3__* %30, i32 0)
%32 = load i64, i64* @REG_NOMATCH
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %62
34: ; preds = %28
%35 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %9, i64 0, i64 1
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %9, i64 0, i64 1
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %39, i32 0, i32 1
%41 = load i64, i64* %40
%42 = sub i64 %38, %41
%43 = trunc i64 %42 to i32
store i32 %43, i32* %12
%44 = load i32, i32* %5
%45 = load i32, i32* %12
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %34
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %12
br label %50
50: ; preds = %47, %34
%51 = load i8*, i8** %4
%52 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %9, i64 0, i64 1
%53 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i32 0, i32 1
%54 = load i64, i64* %53
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %54
%56 = load i32, i32* %12
%57 = call i32 @strncpy(i8* %51, i8* %55, i32 %56)
%58 = load i8*, i8** %4
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
store i32 0, i32* %6
br label %63
62: ; preds = %28
br label %23
63: ; preds = %50, %23
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
br label %66
66: ; preds = %63, %19
%67 = call i32 @regfree(i32* %8)
%68 = load i32, i32* %6
store i32 %68, i32* %3
br label %69
69: ; preds = %66, %17
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64 }
@.str = [65 x i8] c"^[[:space:]]*systemIdPath[[:space:]]*=[[:space:]]*([[:print:]]+)\00"
@REG_EXTENDED = global i32 0
@.str.1 = [27 x i8] c"/etc/sysconfig/rhn/up2date\00"
@.str.2 = [2 x i8] c"r\00"
@REG_NOMATCH = global i64 0
define i32 @parse_systemid_path(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [2 x %struct.TYPE_3__]
%5 = alloca [1024 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast [2 x %struct.TYPE_3__]* %4 to i8*
%8 = load i32, i32* @REG_EXTENDED
%9 = call i64 @regcomp(i32* %3, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %2
%12 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %41, label %14
14: ; preds = %11
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %4, i64 0, i64 0
br label %17
17: ; preds = %20, %14
%18 = call i32* @fgets(i8* %15, i32 1024, i32* %12)
%19 = icmp eq i32* %18, null
br i1 %19, label %38, label %20
20: ; preds = %17
%21 = call i64 @regexec(i32* %3, i8* %15, i32 2, %struct.TYPE_3__* %16, i32 0)
%22 = load i64, i64* @REG_NOMATCH
%23 = icmp eq i64 %21, %22
br i1 %23, label %17, label %24
24: ; preds = %20
%25 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %4, i64 0, i64 1, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %4, i64 0, i64 1, i32 1
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = sub i32 %26, %29
%31 = icmp sgt i32 %30, %1
%32 = add nsw i32 %1, -1
%33 = select i1 %31, i32 %32, i32 %30
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %28
%35 = call i32 @strncpy(i8* %0, i8* %34, i32 %33)
%36 = sext i32 %33 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %17, %24
%39 = phi i32 [ 0, %24 ], [ 1, %17 ]
%40 = call i32 @fclose(i32* %12)
br label %41
41: ; preds = %38, %11
%42 = phi i32 [ %39, %38 ], [ 1, %11 ]
%43 = call i32 @regfree(i32* %3)
br label %44
44: ; preds = %2, %41
%45 = phi i32 [ %42, %41 ], [ 1, %2 ]
ret i32 %45
}