#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*/ printExitFailure(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(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) {
    printExitFailure("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) {
    printExitFailure("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) {
    printExitFailure("Token nicht gefunden");
  }
  char *newline = strchr(klaus, '\n');
  if (newline != NULL) {
    *newline = '\0';
  }
  *out = calloc(strlen(klaus) + 1, sizeof(char));
  if (*out == NULL) {
    printExitFailure("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    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c9 <extractCGIdata+0x39>
cmpq   $0x0,-0x18(%rbp)
je     11c9 <extractCGIdata+0x39>
cmpq   $0x0,-0x20(%rbp)
jne    11d5 <extractCGIdata+0x45>
lea    0xe30(%rip),%rdi
call   1070 <printExitFailure@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   1080 <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   1080 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1236 <extractCGIdata+0xa6>
cmpq   $0x0,-0x38(%rbp)
jne    1242 <extractCGIdata+0xb2>
lea    0xdf3(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   10a0 <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   10b0 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    129c <extractCGIdata+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    136e <extractCGIdata+0x1de>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12e5 <extractCGIdata+0x155>
lea    0xd7d(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    -0x48(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1309 <extractCGIdata+0x179>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1345 <extractCGIdata+0x1b5>
lea    0xcf0(%rip),%rdi
call   1070 <printExitFailure@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    $0x60,%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,%rbx
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
test   %rdi,%rdi
je     11b6 <extractCGIdata+0x26>
test   %rbp,%rbp
je     11b6 <extractCGIdata+0x26>
test   %r12,%r12
jne    11c2 <extractCGIdata+0x32>
lea    0xe43(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
test   %r14,%r14
je     11fc <extractCGIdata+0x6c>
test   %r15,%r15
jne    1208 <extractCGIdata+0x78>
lea    0xe2d(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     12d3 <extractCGIdata+0x143>
mov    %rbx,%r13
mov    %rax,%rdi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
test   %rbx,%rbx
jne    1271 <extractCGIdata+0xe1>
lea    0xdf1(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1286 <extractCGIdata+0xf6>
movb   $0x0,(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,0x0(%r13)
test   %rax,%rax
jne    12b4 <extractCGIdata+0x124>
lea    0xd85(%rip),%rdi
call   1070 <printExitFailure@plt>
mov    0x0(%r13),%rax
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12d8 <extractCGIdata+0x148>
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*
%14 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20, %17, %4
%24 = call i32 @printExitFailure(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
store i8* null, i8** %10
%26 = load i8*, i8** %7
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = add nsw i32 %28, 1
%30 = call i8* @calloc(i32 %29, i32 1)
store i8* %30, i8** %10
store i8* null, i8** %11
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = call i8* @calloc(i32 %33, i32 1)
store i8* %34, i8** %11
%35 = load i8*, i8** %10
%36 = icmp eq i8* %35, null
br i1 %36, label %40, label %37
37: ; preds = %25
%38 = load i8*, i8** %11
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %37, %25
%41 = call i32 @printExitFailure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i8*, i8** %10
%44 = load i8*, i8** %7
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i8*, i8** %10
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8*, i8** %11
%49 = load i8*, i8** %6
%50 = call i32 @strcpy(i8* %48, i8* %49)
store i8* null, i8** %12
%51 = load i8*, i8** %11
%52 = load i8*, i8** %10
%53 = call i8* @strstr(i8* %51, i8* %52)
store i8* %53, i8** %12
%54 = load i8*, i8** %12
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %57
56: ; preds = %42
store i32 -1, i32* %5
br label %96
57: ; preds = %42
store i8* null, i8** %13
%58 = load i8*, i8** %12
%59 = load i8*, i8** %8
%60 = call i8* @strtok(i8* %58, i8* %59)
%61 = load i8*, i8** %10
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
store i8* %64, i8** %13
%65 = load i8*, i8** %13
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %69
67: ; preds = %57
%68 = call i32 @printExitFailure(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %57
%70 = load i8*, i8** %13
%71 = call i8* @strchr(i8* %70, i8 signext 10)
store i8* %71, i8** %14
%72 = load i8*, i8** %14
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = load i8*, i8** %14
store i8 0, i8* %75
br label %76
76: ; preds = %74, %69
%77 = load i8*, i8** %13
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %78, 1
%80 = call i8* @calloc(i32 %79, i32 1)
%81 = load i8**, i8*** %9
store i8* %80, i8** %81
%82 = load i8**, i8*** %9
%83 = load i8*, i8** %82
%84 = icmp eq i8* %83, null
br i1 %84, label %85, label %87
85: ; preds = %76
%86 = call i32 @printExitFailure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %85, %76
%88 = load i8**, i8*** %9
%89 = load i8*, i8** %88
%90 = load i8*, i8** %13
%91 = call i32 @strcpy(i8* %89, i8* %90)
%92 = load i8*, i8** %10
%93 = call i32 @free(i8* %92)
%94 = load i8*, i8** %11
%95 = call i32 @free(i8* %94)
store i32 0, i32* %5
br label %96
96: ; preds = %87, %56
%97 = load i32, i32* %5
ret i32 %97
}

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 @printExitFailure(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 @printExitFailure(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 %55, 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 @printExitFailure(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 i8* @strchr(i8* dereferenceable(1) %34, i8 signext 10)
%40 = icmp eq i8* %39, null
br i1 %40, label %42, label %41
41: ; preds = %38
store i8 0, i8* %39
br label %42
42: ; preds = %41, %38
%43 = tail call i32 @strlen(i8* %34)
%44 = add nsw i32 %43, 1
%45 = tail call i8* @calloc(i32 %44, i32 1)
store i8* %45, i8** %3
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = tail call i32 @printExitFailure(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%49 = load i8*, i8** %3
br label %50
50: ; preds = %47, %42
%51 = phi i8* [ %49, %47 ], [ %45, %42 ]
%52 = tail call i32 @strcpy(i8* %51, i8* %34)
%53 = tail call i32 @free(i8* %15)
%54 = tail call i32 @free(i8* %18)
br label %55
55: ; preds = %24, %50
%56 = phi i32 [ 0, %50 ], [ -1, %24 ]
ret i32 %56
}