#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 /*<<< orphan*/ exit(int);
void *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char **simple_parse(char *src, int *num) {
  char **res;
  char *ptr;
  int i;
  res = malloc(sizeof(char *) * 20);
  ptr = strtok(src, " ");
  for (i = 0; ptr != NULL; i++) {
    if (i >= 20) {
      printf("Too many parameters!\n");
      exit(1);
    }
    res[i] = malloc(strlen(ptr) + 1);
    strcpy(res[i], ptr);
    ptr = strtok(NULL, " ");
  }
  res[i] = NULL;
  *num = i;
  return res;
}


x86 assembly (clang, -O0):
<simple_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xa0,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     121d <simple_parse+0xbd>
cmpl   $0x14,-0x24(%rbp)
jl     11c4 <simple_parse+0x64>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfa(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <simple_parse+0x39>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_parse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xa0,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11dd <simple_parse+0x7d>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe64(%rip),%r15
nopl   0x0(%rax)
cmp    $0x14,%rbx
je     11f9 <simple_parse+0x99>
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%r13
add    $0x1,%rbx
test   %rax,%rax
jne    11a0 <simple_parse+0x40>
jmp    11df <simple_parse+0x7f>
xor    %ebx,%ebx
mov    %ebx,%eax
movq   $0x0,(%r12,%rax,8)
mov    %ebx,(%r14)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [22 x i8] c"Too many parameters!\0A\00"
define i8** @simple_parse(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = call i8* @malloc(i32 160)
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %5
%10 = load i8*, i8** %3
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
store i32 0, i32* %7
br label %12
12: ; preds = %38, %2
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 20
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = call i8* @malloc(i32 %24)
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %25, i8** %29
%30 = load i8**, i8*** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = load i8*, i8** %6
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %6
br label %38
38: ; preds = %21
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %12
41: ; preds = %12
%42 = load i8**, i8*** %5
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
store i8* null, i8** %45
%46 = load i32, i32* %7
%47 = load i32*, i32** %4
store i32 %46, i32* %47
%48 = load i8**, i8*** %5
ret i8** %48
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@str = [21 x i8] c"Too many parameters!\00"
define noalias i8** @simple_parse(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call dereferenceable_or_null(160) i8* @malloc(i32 160)
%4 = bitcast i8* %3 to i8**
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %25, label %7
7: ; preds = %2, %14
%8 = phi i64 [ %21, %14 ], [ 0, %2 ]
%9 = phi i8* [ %20, %14 ], [ %5, %2 ]
%10 = icmp eq i64 %8, 20
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = tail call i32 @strlen(i8* %9)
%16 = add nsw i32 %15, 1
%17 = tail call i8* @malloc(i32 %16)
%18 = getelementptr inbounds i8*, i8** %4, i64 %8
store i8* %17, i8** %18
%19 = tail call i32 @strcpy(i8* %17, i8* %9)
%20 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = add nuw nsw i64 %8, 1
%22 = icmp eq i8* %20, null
br i1 %22, label %23, label %7
23: ; preds = %14
%24 = trunc i64 %21 to i32
br label %25
25: ; preds = %23, %2
%26 = phi i32 [ 0, %2 ], [ %24, %23 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %4, i64 %27
store i8* null, i8** %28
store i32 %26, i32* %1
ret i8** %4
}