#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 */
int strcspn(char *, char *);
int my_split(char *bigstr, char **needle, char *delim, int maxsplit) {
  int i;
  for (i = 0; i < maxsplit; i++) {
    int n;
    needle[i] = bigstr;
    n = strcspn(bigstr, delim);
    if (bigstr[n] == 0) {
      i++;
      break;
    }
    bigstr[n] = 0;
    bigstr += n;
    bigstr++;
  }
  return i;
}


x86 assembly (clang, -O0):
<my_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b4 <my_split+0xa4>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117d <my_split+0x6d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <my_split+0xa4>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <my_split+0x1e>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_split>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    115f <my_split+0x4f>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%r13d
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %rbx,(%r15,%r12,8)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1164 <my_split+0x54>
add    %rax,%rbx
movb   $0x0,(%rbx)
add    $0x1,%rbx
add    $0x1,%r12
cmp    %r12,%r13
jne    1130 <my_split+0x20>
mov    %r13d,%r12d
jmp    1168 <my_split+0x58>
xor    %r12d,%r12d
jmp    1168 <my_split+0x58>
add    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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