#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 atoi(char *);
char *strchr(char *, char);
int skill_split_atoi(char *str, int *val, int num) {
  int i, max = 0;
  for (i = 0; i < num; i++) {
    if (str) {
      val[i] = max = atoi(str);
      str = strchr(str, ':');
      if (str)
        *str++ = 0;
    } else {
      val[i] = max;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<skill_split_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c6 <skill_split_atoi+0xa6>
cmpq   $0x0,-0x8(%rbp)
je     11a5 <skill_split_atoi+0x85>
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a0 <skill_split_atoi+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
jmp    11b3 <skill_split_atoi+0x93>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11b8 <skill_split_atoi+0x98>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1141 <skill_split_atoi+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skill_split_atoi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1191 <skill_split_atoi+0x71>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %edx,%r12d
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    115f <skill_split_atoi+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,(%r15,%rbx,4)
xor    %ebp,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
je     1194 <skill_split_atoi+0x74>
test   %rbp,%rbp
je     1150 <skill_split_atoi+0x30>
mov    %rbp,%rdi
call   1040 <atoi@plt>
mov    %eax,%r13d
mov    %eax,(%r15,%rbx,4)
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1154 <skill_split_atoi+0x34>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
jmp    1156 <skill_split_atoi+0x36>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @skill_split_atoi(i8* %0, i32* 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, %21
%8 = phi i64 [ 0, %5 ], [ %24, %21 ]
%9 = phi i32 [ 0, %5 ], [ %23, %21 ]
%10 = phi i8* [ %0, %5 ], [ %22, %21 ]
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = tail call i32 @atoi(i8* %10)
%14 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %13, i32* %14
%15 = tail call i8* @strchr(i8* %10, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %15
br label %21
19: ; preds = %7
%20 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %9, i32* %20
br label %21
21: ; preds = %19, %17, %12
%22 = phi i8* [ %18, %17 ], [ null, %12 ], [ null, %19 ]
%23 = phi i32 [ %13, %17 ], [ %13, %12 ], [ %9, %19 ]
%24 = add nuw nsw i64 %8, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %26, label %7
26: ; preds = %21, %3
%27 = phi i32 [ 0, %3 ], [ %2, %21 ]
ret i32 %27
}