#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 *malloc(int);
char *strtok(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int *cut_up(char *haystack) {
  int *ret_val = malloc(2 * sizeof(int));
  char *token = strtok(haystack, " ");
  int idx = 0;
  while (token) {
    ret_val[idx] = strtol(token, NULL, 10);
    idx++;
    token = strtok(NULL, " ");
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<cut_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <cut_up+0x81>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1165 <cut_up+0x35>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_up>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     1194 <cut_up+0x64>
lea    0xea0(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,(%rbx)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    1170 <cut_up+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i32* @cut_up(i8* %0) {
%2 = tail call i32* @malloc(i32 8)
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %10, %5 ], [ 0, %1 ]
%7 = phi i8* [ %11, %5 ], [ %3, %1 ]
%8 = tail call i32 @strtol(i8* nocapture %7, i32* null, i32 10)
%9 = getelementptr inbounds i32, i32* %2, i64 %6
store i32 %8, i32* %9
%10 = add nuw i64 %6, 1
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %5
13: ; preds = %5, %1
ret i32* %2
}