#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 *);
scalar_t__ malloc(int const);
char *strtok(char *const, char *);
int *split_line(char *const string, int const width) {
  int *values = (int *)malloc(width * sizeof(int));
  char *value;
  int i = 0;
  value = strtok(string, " ");
  while (value != NULL) {
    values[i] = atoi(value);
    i++;
    value = strtok(NULL, " ");
  }
  if (i != width)
    return (int *)-1;
  else
    return values;
}


x86 assembly (clang, -O0):
<split_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b0 <split_line+0x80>
mov    -0x28(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5e(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    116d <split_line+0x3d>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11cc <split_line+0x9c>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <split_line+0xa4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
lea    0xeab(%rip),%rsi
mov    %r15,%rdi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     118f <split_line+0x5f>
lea    0xe95(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1170 <split_line+0x40>
cmp    %r14d,%ebx
mov    $0xffffffffffffffff,%rax
cmove  %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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