#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 *StrUtil_copyString(char **, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
char *prefixParser(char *header, char *delim, char *prefix, char *routine) {
  char *token;
  char workStr[1024];
  char *retToken;
  int len = strlen(prefix);
  strcpy(workStr, header);
  token = strtok(workStr + 1, delim);
  while (token && strncmp(token, prefix, len)) {
    token = strtok(NULL, delim);
  }
  if (token == NULL) {
    printf("Error parsing ID in %s from string %s\n", routine, header);
  }
  retToken = StrUtil_copyString(&retToken, token, len);
  return retToken;
}


x86 assembly (clang, -O0):
<prefixParser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x43c(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x430(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x43d(%rbp)
je     11e5 <prefixParser+0x85>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x43c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x43d(%rbp)
mov    -0x43d(%rbp),%al
test   $0x1,%al
jne    11f8 <prefixParser+0x98>
jmp    120e <prefixParser+0xae>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11b2 <prefixParser+0x52>
cmpq   $0x0,-0x28(%rbp)
jne    122d <prefixParser+0xcd>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xdd8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x43c(%rbp),%edx
lea    -0x438(%rbp),%rdi
call   1070 <StrUtil_copyString@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefixParser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0x11(%rsp),%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11d5 <prefixParser+0x75>
mov    %rax,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e9 <prefixParser+0x89>
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11b0 <prefixParser+0x50>
lea    0xe24(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <printf@plt>
xor    %ebp,%ebp
lea    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1070 <StrUtil_copyString@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Error parsing ID in %s from string %s\0A\00"
define i8* @prefixParser(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8*, i8** %6
%21 = call i8* @strtok(i8* %19, i8* %20)
store i8* %21, i8** %9
br label %22
22: ; preds = %33, %4
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8*, i8** %9
%27 = load i8*, i8** %7
%28 = load i32, i32* %12
%29 = call i64 @strncmp(i8* %26, i8* %27, i32 %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %25, %22
%32 = phi i1 [ false, %22 ], [ %30, %25 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %6
%35 = call i8* @strtok(i8* null, i8* %34)
store i8* %35, i8** %9
br label %22
36: ; preds = %31
%37 = load i8*, i8** %9
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i8*, i8** %8
%41 = load i8*, i8** %5
%42 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %40, i8* %41)
br label %43
43: ; preds = %39, %36
%44 = load i8*, i8** %9
%45 = load i32, i32* %12
%46 = call i8* @StrUtil_copyString(i8** %11, i8* %44, i32 %45)
store i8* %46, i8** %11
%47 = load i8*, i8** %11
ret i8* %47
}

LLVM IR (-O2):
@.str = [39 x i8] c"Error parsing ID in %s from string %s\0A\00"
define i8* @prefixParser(i8* %0, i8* nocapture %1, i8* %2, i8* %3) {
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = bitcast i8** %6 to i8*
%9 = tail call i32 @strlen(i8* %2)
%10 = call i32 @strcpy(i8* %7, i8* %0)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 1
%12 = call i8* @strtok(i8* %11, i8* %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %4, %18
%15 = phi i8* [ %19, %18 ], [ %12, %4 ]
%16 = call i64 @strncmp(i8* %15, i8* %2, i32 %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = call i8* @strtok(i8* null, i8* %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %14
21: ; preds = %18, %4
%22 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %0)
br label %23
23: ; preds = %14, %21
%24 = phi i8* [ null, %21 ], [ %15, %14 ]
%25 = call i8* @StrUtil_copyString(i8** %6, i8* %24, i32 %9)
ret i8* %25
}