#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 */
unsigned char *strchr(unsigned char *, char);
int OF_split_args(unsigned char *args, unsigned char **argv, int max_args) {
  unsigned char *pos, *end;
  int i;
  pos = args;
  end = pos;
  for (i = 0; i < max_args && *pos != '\0' && end != NULL; i++) {
    end = strchr(pos, ',');
    if (end != NULL)
      *end = '\0';
    argv[i] = pos;
    pos = end + 1;
  }
  return i;
}


x86 assembly (clang, -O0):
<OF_split_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    116b <OF_split_args+0x5b>
mov    -0x20(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     116b <OF_split_args+0x5b>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    117b <OF_split_args+0x6b>
jmp    11c9 <OF_split_args+0xb9>
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119f <OF_split_args+0x8f>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113a <OF_split_args+0x2a>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OF_split_args>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1165 <OF_split_args+0x55>
mov    %rsi,%r14
mov    %rdi,%rax
mov    %edx,%r12d
xor    %r15d,%r15d
mov    %rdi,%rbx
jmp    1144 <OF_split_args+0x34>
nopl   (%rax)
mov    %rbx,(%r14,%r15,8)
mov    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%r15
cmp    %r15,%r12
je     116a <OF_split_args+0x5a>
cmpb   $0x0,(%rbx)
je     116d <OF_split_args+0x5d>
test   %rax,%rax
je     116d <OF_split_args+0x5d>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1130 <OF_split_args+0x20>
movb   $0x0,(%rax)
jmp    1130 <OF_split_args+0x20>
xor    %r15d,%r15d
jmp    116d <OF_split_args+0x5d>
mov    %r12d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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