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


x86 assembly (clang, -O0):
<tokenParser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b4 <tokenParser+0x74>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <tokenParser+0x49>
cmpq   $0x0,-0x30(%rbp)
jne    11d3 <tokenParser+0x93>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    -0x438(%rbp),%rdi
xor    %edx,%edx
call   1050 <StrUtil_copyString@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenParser>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x11(%rsp),%rdi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %ebp,%ebp
jle    118f <tokenParser+0x4f>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
add    $0xffffffff,%ebp
jne    1180 <tokenParser+0x40>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <tokenParser+0x69>
lea    0xe62(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <StrUtil_copyString@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
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* @tokenParser(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [1024 x i8]
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8*, i8** %6
%19 = call i8* @strtok(i8* %17, i8* %18)
store i8* %19, i8** %10
store i32 0, i32* %9
br label %20
20: ; preds = %27, %4
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = call i8* @strtok(i8* null, i8* %25)
store i8* %26, i8** %10
br label %27
27: ; preds = %24
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %20
30: ; preds = %20
%31 = load i8*, i8** %10
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i8*, i8** %5
%36 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %30
%38 = load i8*, i8** %10
%39 = call i8* @StrUtil_copyString(i8** %12, i8* %38, i32 0)
store i8* %39, i8** %12
%40 = load i8*, i8** %12
ret i8* %40
}

LLVM IR (-O2):
@.str = [39 x i8] c"Error parsing ID in %s from string %s\0A\00"
define i8* @tokenParser(i8* %0, i8* nocapture %1, i32 %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 = call i32 @strcpy(i8* %7, i8* %0)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 1
%11 = call i8* @strtok(i8* %10, i8* %1)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %18
13: ; preds = %4, %13
%14 = phi i32 [ %16, %13 ], [ 0, %4 ]
%15 = call i8* @strtok(i8* null, i8* %1)
%16 = add nuw nsw i32 %14, 1
%17 = icmp eq i32 %16, %2
br i1 %17, label %18, label %13
18: ; preds = %13, %4
%19 = phi i8* [ %11, %4 ], [ %15, %13 ]
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%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 = %21, %18
%24 = call i8* @StrUtil_copyString(i8** %6, i8* %19, i32 0)
ret i8* %24
}