#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 *strchr(char *, char);
char *strtok(char *, char *);
char *SplitString(char *content, char *split, int pos) {
  char *ptr;
  int i = 1;
  ptr = strtok(content, split);
  if (1 == pos) {
    return ptr;
  }
  while (ptr != NULL) {
    i++;
    ptr = strtok(NULL, split);
    char *findChr = strchr(ptr, *split);
    if (NULL == findChr) {
      return NULL;
    }
    if (i == pos) {
      return ptr;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<SplitString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jne    1166 <SplitString+0x46>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <SplitString+0xc3>
jmp    116b <SplitString+0x4b>
cmpq   $0x0,-0x28(%rbp)
je     11db <SplitString+0xbb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11bd <SplitString+0x9d>
movq   $0x0,-0x8(%rbp)
jmp    11e3 <SplitString+0xc3>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11d6 <SplitString+0xb6>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <SplitString+0xc3>
jmp    116b <SplitString+0x4b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SplitString>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
call   1040 <strtok@plt>
mov    %rax,%rbx
cmp    $0x1,%ebp
jne    113b <SplitString+0x1b>
mov    %rbx,%rax
jmp    1177 <SplitString+0x57>
add    $0xffffffff,%ebp
xchg   %ax,%ax
test   %rbx,%rbx
je     1175 <SplitString+0x55>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
movsbl (%r14),%esi
mov    %rax,%rdi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    $0x0,%eax
test   %rcx,%rcx
je     1177 <SplitString+0x57>
mov    %rbx,%rax
add    $0xffffffff,%ebp
jne    1140 <SplitString+0x20>
jmp    1177 <SplitString+0x57>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @SplitString(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 1, i32* %9
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i8* @strtok(i8* %11, i8* %12)
store i8* %13, i8** %8
%14 = load i32, i32* %7
%15 = icmp eq i32 1, %14
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i8*, i8** %8
store i8* %17, i8** %4
br label %42
18: ; preds = %3
br label %19
19: ; preds = %40, %18
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %41
22: ; preds = %19
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
%25 = load i8*, i8** %6
%26 = call i8* @strtok(i8* null, i8* %25)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = call i8* @strchr(i8* %27, i8 signext %29)
store i8* %30, i8** %10
%31 = load i8*, i8** %10
%32 = icmp eq i8* null, %31
br i1 %32, label %33, label %34
33: ; preds = %22
store i8* null, i8** %4
br label %42
34: ; preds = %22
%35 = load i32, i32* %9
%36 = load i32, i32* %7
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = load i8*, i8** %8
store i8* %39, i8** %4
br label %42
40: ; preds = %34
br label %19
41: ; preds = %19
store i8* null, i8** %4
br label %42
42: ; preds = %41, %38, %33, %16
%43 = load i8*, i8** %4
ret i8* %43
}

LLVM IR (-O2):
define i8* @SplitString(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strtok(i8* %0, i8* %1)
%5 = icmp eq i32 %2, 1
br i1 %5, label %18, label %6
6: ; preds = %3, %16
%7 = phi i8* [ %12, %16 ], [ %4, %3 ]
%8 = phi i32 [ %11, %16 ], [ 1, %3 ]
%9 = icmp eq i8* %7, null
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = add nuw nsw i32 %8, 1
%12 = tail call i8* @strtok(i8* null, i8* %1)
%13 = load i8, i8* %1
%14 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = icmp eq i32 %11, %2
br i1 %17, label %18, label %6
18: ; preds = %10, %6, %16, %3
%19 = phi i8* [ %4, %3 ], [ null, %10 ], [ null, %6 ], [ %12, %16 ]
ret i8* %19
}