#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 */

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ print_exit_failure(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int _extractCGIdata(char *data, const char *property, char *delim, char **out) {
  if (data == NULL || property == NULL || delim == NULL) {
    print_exit_failure("Eingabeparameter von extractCGIdata sind falsch");
  }
  char *prop = NULL;
  prop = (char *)calloc(strlen(property) + 1 + 1, sizeof(char));
  char *tempData = NULL;
  tempData = (char *)calloc(strlen(data) + 1, sizeof(char));
  if (prop == NULL || tempData == NULL) {
    print_exit_failure("Es konnte kein Speicher angefordert werden");
  }
  strcpy(prop, property);
  strcat(prop, "=");
  strcpy(tempData, data);
  char *start = NULL;
  start = strstr(tempData, prop);
  if (start == NULL) {
    return -1;
  }
  char *klaus = NULL;
  klaus = strtok(start, delim) + strlen(prop);
  if (klaus == NULL) {
    print_exit_failure("Token nicht gefunden");
  }
  *out = calloc(strlen(klaus) + 1, sizeof(char));
  if (*out == NULL) {
    print_exit_failure("Es konnte kein Speicher angefordert werden");
  }
  strcpy(*out, klaus);
  free(prop);
  free(tempData);
  return 0;
}


x86 assembly (clang, -O0):
<_extractCGIdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b9 <_extractCGIdata+0x39>
cmpq   $0x0,-0x18(%rbp)
je     11b9 <_extractCGIdata+0x39>
cmpq   $0x0,-0x20(%rbp)
jne    11c5 <_extractCGIdata+0x45>
lea    0xe40(%rip),%rdi
call   1070 <print_exit_failure@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1226 <_extractCGIdata+0xa6>
cmpq   $0x0,-0x38(%rbp)
jne    1232 <_extractCGIdata+0xb2>
lea    0xe03(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    128c <_extractCGIdata+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    133a <_extractCGIdata+0x1ba>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12d5 <_extractCGIdata+0x155>
lea    0xd8d(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1311 <_extractCGIdata+0x191>
lea    0xd24(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_extractCGIdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
test   %rdi,%rdi
je     11a6 <_extractCGIdata+0x26>
test   %rbp,%rbp
je     11a6 <_extractCGIdata+0x26>
test   %r12,%r12
jne    11b2 <_extractCGIdata+0x32>
lea    0xe53(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     11ec <_extractCGIdata+0x6c>
test   %r15,%r15
jne    11f8 <_extractCGIdata+0x78>
lea    0xe3d(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     12a5 <_extractCGIdata+0x125>
mov    %rax,%rdi
mov    %r12,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%r12
add    %rbp,%r12
test   %rbp,%rbp
jne    125a <_extractCGIdata+0xda>
lea    0xe08(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    1286 <_extractCGIdata+0x106>
lea    0xdb2(%rip),%rdi
call   1070 <print_exit_failure@plt>
mov    (%r14),%rax
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12aa <_extractCGIdata+0x12a>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Eingabeparameter von extractCGIdata sind falsch\00"
@.str.1 = [43 x i8] c"Es konnte kein Speicher angefordert werden\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [21 x i8] c"Token nicht gefunden\00"
define i32 @_extractCGIdata(i8* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %16, %4
%23 = call i32 @print_exit_failure(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
store i8* null, i8** %10
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = add nsw i32 %27, 1
%29 = call i8* @calloc(i32 %28, i32 1)
store i8* %29, i8** %10
store i8* null, i8** %11
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
%33 = call i8* @calloc(i32 %32, i32 1)
store i8* %33, i8** %11
%34 = load i8*, i8** %10
%35 = icmp eq i8* %34, null
br i1 %35, label %39, label %36
36: ; preds = %24
%37 = load i8*, i8** %11
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %36, %24
%40 = call i32 @print_exit_failure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = load i8*, i8** %10
%43 = load i8*, i8** %7
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %10
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load i8*, i8** %11
%48 = load i8*, i8** %6
%49 = call i32 @strcpy(i8* %47, i8* %48)
store i8* null, i8** %12
%50 = load i8*, i8** %11
%51 = load i8*, i8** %10
%52 = call i8* @strstr(i8* %50, i8* %51)
store i8* %52, i8** %12
%53 = load i8*, i8** %12
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %56
55: ; preds = %41
store i32 -1, i32* %5
br label %88
56: ; preds = %41
store i8* null, i8** %13
%57 = load i8*, i8** %12
%58 = load i8*, i8** %8
%59 = call i8* @strtok(i8* %57, i8* %58)
%60 = load i8*, i8** %10
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8* %63, i8** %13
%64 = load i8*, i8** %13
%65 = icmp eq i8* %64, null
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = call i32 @print_exit_failure(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %68
68: ; preds = %66, %56
%69 = load i8*, i8** %13
%70 = call i32 @strlen(i8* %69)
%71 = add nsw i32 %70, 1
%72 = call i8* @calloc(i32 %71, i32 1)
%73 = load i8**, i8*** %9
store i8* %72, i8** %73
%74 = load i8**, i8*** %9
%75 = load i8*, i8** %74
%76 = icmp eq i8* %75, null
br i1 %76, label %77, label %79
77: ; preds = %68
%78 = call i32 @print_exit_failure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %79
79: ; preds = %77, %68
%80 = load i8**, i8*** %9
%81 = load i8*, i8** %80
%82 = load i8*, i8** %13
%83 = call i32 @strcpy(i8* %81, i8* %82)
%84 = load i8*, i8** %10
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %11
%87 = call i32 @free(i8* %86)
store i32 0, i32* %5
br label %88
88: ; preds = %79, %55
%89 = load i32, i32* %5
ret i32 %89
}

LLVM IR (-O2):
@.str = [48 x i8] c"Eingabeparameter von extractCGIdata sind falsch\00"
@.str.1 = [43 x i8] c"Es konnte kein Speicher angefordert werden\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [21 x i8] c"Token nicht gefunden\00"
define i32 @_extractCGIdata(i8* %0, i8* %1, i8* %2, i8** nocapture %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
%8 = icmp eq i8* %2, null
%9 = or i1 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @print_exit_failure(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %4, %10
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, 2
%15 = tail call i8* @calloc(i32 %14, i32 1)
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, 1
%18 = tail call i8* @calloc(i32 %17, i32 1)
%19 = icmp eq i8* %15, null
%20 = icmp eq i8* %18, null
%21 = or i1 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @print_exit_failure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %12, %22
%25 = tail call i32 @strcpy(i8* %15, i8* %1)
%26 = tail call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @strcpy(i8* %18, i8* %0)
%28 = tail call i8* @strstr(i8* dereferenceable(1) %18, i8* dereferenceable(1) %15)
%29 = icmp eq i8* %28, null
br i1 %29, label %51, label %30
30: ; preds = %24
%31 = tail call i8* @strtok(i8* %28, i8* %2)
%32 = tail call i32 @strlen(i8* %15)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = icmp eq i8* %31, null
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = tail call i32 @print_exit_failure(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
%39 = tail call i32 @strlen(i8* %34)
%40 = add nsw i32 %39, 1
%41 = tail call i8* @calloc(i32 %40, i32 1)
store i8* %41, i8** %3
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = tail call i32 @print_exit_failure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%45 = load i8*, i8** %3
br label %46
46: ; preds = %43, %38
%47 = phi i8* [ %45, %43 ], [ %41, %38 ]
%48 = tail call i32 @strcpy(i8* %47, i8* %34)
%49 = tail call i32 @free(i8* %15)
%50 = tail call i32 @free(i8* %18)
br label %51
51: ; preds = %24, %46
%52 = phi i32 [ 0, %46 ], [ -1, %24 ]
ret i32 %52
}