#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 *strtok(char *, char *);
int parse_args(int argc, char **argv, char *args) {
  int i = 1;
  argv[0] = strtok(args, ":");
  while ((argv[i] = strtok(NULL, ":"))) {
    i++;
    if (i > (argc - 1)) {
      return -i;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xecb(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xeb1(%rip),%rsi
call   1030 <strtok@plt>
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     1196 <parse_args+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1191 <parse_args+0x81>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <parse_args+0x8c>
jmp    1144 <parse_args+0x34>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xedc(%rip),%r14
mov    %rdx,%rdi
mov    %r14,%rsi
call   1030 <strtok@plt>
mov    %rax,(%r15)
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
mov    $0x1,%eax
cmovge %ebx,%eax
add    $0x1,%eax
mov    $0x1,%ebx
mov    $0x1,%r12d
sub    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     1187 <parse_args+0x77>
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1160 <parse_args+0x50>
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define i32 @parse_args(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32 1, i32* %8
%9 = load i8*, i8** %7
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = load i8**, i8*** %6
%12 = getelementptr inbounds i8*, i8** %11, i64 0
store i8* %10, i8** %12
br label %13
13: ; preds = %30, %3
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = load i8**, i8*** %6
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
store i8* %14, i8** %18
%19 = icmp ne i8* %14, null
br i1 %19, label %20, label %31
20: ; preds = %13
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = icmp sgt i32 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* %8
%29 = sub nsw i32 0, %28
store i32 %29, i32* %4
br label %33
30: ; preds = %20
br label %13
31: ; preds = %13
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %27
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define i32 @parse_args(i32 %0, i8** nocapture writeonly %1, i8* %2) {
%4 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = add i32 %0, -1
%6 = call i32 @llvm.smax.i32(i32 %5, i32 1)
%7 = add nuw i32 %6, 1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %14, %3
%10 = phi i64 [ %15, %14 ], [ 1, %3 ]
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
store i8* %11, i8** %12
%13 = icmp eq i8* %11, null
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %17, label %9
17: ; preds = %14
%18 = trunc i64 %10 to i32
%19 = xor i32 %18, -1
br label %22
20: ; preds = %9
%21 = trunc i64 %10 to i32
br label %22
22: ; preds = %20, %17
%23 = phi i32 [ %19, %17 ], [ %21, %20 ]
ret i32 %23
}