#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);
int roadmap_input_split(char *text, char separator, char *field[], int max) {
  int i;
  char *p;
  field[0] = text;
  p = strchr(text, separator);
  for (i = 1; p != NULL && *p != 0; ++i) {
    *p = 0;
    if (i >= max)
      return -1;
    field[i] = ++p;
    p = strchr(p, separator);
  }
  return i;
}


x86 assembly (clang, -O0):
<roadmap_input_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
je     116c <roadmap_input_split+0x5c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117c <roadmap_input_split+0x6c>
jmp    11d2 <roadmap_input_split+0xc2>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     119b <roadmap_input_split+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <roadmap_input_split+0xc8>
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114c <roadmap_input_split+0x3c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roadmap_input_split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,(%rdx)
call   1030 <strchr@plt>
test   %rax,%rax
je     116b <roadmap_input_split+0x5b>
cmp    $0x2,%ebx
mov    $0x1,%ebp
cmovge %ebx,%ebp
mov    $0x1,%ebx
movsbl %r15b,%r15d
cmpb   $0x0,(%rax)
je     1177 <roadmap_input_split+0x67>
movb   $0x0,(%rax)
cmp    %rbx,%rbp
je     1172 <roadmap_input_split+0x62>
add    $0x1,%rax
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rdi
mov    %r15d,%esi
call   1030 <strchr@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <roadmap_input_split+0x30>
jmp    1177 <roadmap_input_split+0x67>
mov    $0x1,%ebx
jmp    1177 <roadmap_input_split+0x67>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @roadmap_input_split(i8* %0, i8 signext %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i8**, i8*** %8
%14 = getelementptr inbounds i8*, i8** %13, i64 0
store i8* %12, i8** %14
%15 = load i8*, i8** %6
%16 = load i8, i8* %7
%17 = call i8* @strchr(i8* %15, i8 signext %16)
store i8* %17, i8** %11
store i32 1, i32* %10
br label %18
18: ; preds = %44, %4
%19 = load i8*, i8** %11
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %11
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br label %26
26: ; preds = %21, %18
%27 = phi i1 [ false, %18 ], [ %25, %21 ]
br i1 %27, label %28, label %47
28: ; preds = %26
%29 = load i8*, i8** %11
store i8 0, i8* %29
%30 = load i32, i32* %10
%31 = load i32, i32* %9
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 -1, i32* %5
br label %49
34: ; preds = %28
%35 = load i8*, i8** %11
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %11
%37 = load i8**, i8*** %8
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = load i8*, i8** %11
%42 = load i8, i8* %7
%43 = call i8* @strchr(i8* %41, i8 signext %42)
store i8* %43, i8** %11
br label %44
44: ; preds = %34
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %18
47: ; preds = %26
%48 = load i32, i32* %10
store i32 %48, i32* %5
br label %49
49: ; preds = %47, %33
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
define i32 @roadmap_input_split(i8* %0, i8 signext %1, i8** nocapture writeonly %2, i32 %3) {
store i8* %0, i8** %2
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = call i32 @llvm.smax.i32(i32 %3, i32 1)
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %17
%11 = phi i64 [ 1, %7 ], [ %21, %17 ]
%12 = phi i8* [ %5, %7 ], [ %20, %17 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %10
store i8 0, i8* %12
%16 = icmp eq i64 %11, %9
br i1 %16, label %27, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = getelementptr inbounds i8*, i8** %2, i64 %11
store i8* %18, i8** %19
%20 = tail call i8* @strchr(i8* %18, i8 signext %1)
%21 = add nuw nsw i64 %11, 1
%22 = icmp eq i8* %20, null
br i1 %22, label %25, label %10
23: ; preds = %10
%24 = trunc i64 %11 to i32
br label %27
25: ; preds = %17
%26 = trunc i64 %21 to i32
br label %27
27: ; preds = %15, %23, %25, %4
%28 = phi i32 [ 1, %4 ], [ %24, %23 ], [ %26, %25 ], [ -1, %15 ]
ret i32 %28
}