#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 const *, char);
char *strndup(char const *, int);
char *opts_split(const char **arg, char delim) {
  char *split = strchr(*arg, delim);
  if (!split) {
    return NULL;
  }
  char *ret = strndup(*arg, split - *arg);
  *arg = split + 1;
  return ret;
}


x86 assembly (clang, -O0):
<opts_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115e <opts_split+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    1195 <opts_split+0x75>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <strndup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opts_split>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%r15
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1151 <opts_split+0x31>
mov    %rax,%rbx
mov    %ebx,%esi
sub    %r15d,%esi
mov    %r15,%rdi
call   1040 <strndup@plt>
add    $0x1,%rbx
mov    %rbx,(%r14)
jmp    1153 <opts_split+0x33>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @opts_split(i8** %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %4
store i8 %1, i8* %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = load i8, i8* %5
%11 = call i8* @strchr(i8* %9, i8 signext %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8* null, i8** %3
br label %30
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = load i8*, i8** %6
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = ptrtoint i8* %18 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = call i8* @strndup(i8* %17, i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8**, i8*** %4
store i8* %27, i8** %28
%29 = load i8*, i8** %7
store i8* %29, i8** %3
br label %30
30: ; preds = %15, %14
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define noalias i8* @opts_split(i8** nocapture %0, i8 signext %1) {
%3 = load i8*, i8** %0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %3 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i8* @strndup(i8* %3, i32 %10)
%12 = getelementptr inbounds i8, i8* %4, i64 1
store i8* %12, i8** %0
br label %13
13: ; preds = %2, %6
%14 = phi i8* [ %11, %6 ], [ null, %2 ]
ret i8* %14
}