#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 */
struct TreeNode {
  int dummy;
};

/* Variables and functions */
struct TreeNode *argv2Tree(int, char **);
char **realloc(char **, int);
char *strtok(char *, char *);
struct TreeNode *str2Tree(char *line, char *sep) {
  int argc;
  char **argv = NULL;
  char *p;
  if (line == NULL) {
    return NULL;
  }
  for (argc = 0, p = strtok(line, sep); p; p = strtok(NULL, sep)) {
    argc++;
    argv = realloc(argv, sizeof(char *) * argc);
    argv[argc - 1] = p;
  }
  return argv2Tree(argc, argv);
}


x86 assembly (clang, -O0):
<str2Tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <str2Tree+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11de <str2Tree+0xae>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ce <str2Tree+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1178 <str2Tree+0x48>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <argv2Tree@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2Tree>:
test   %rdi,%rdi
je     118f <str2Tree+0x5f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <strtok@plt>
test   %rax,%rax
je     1192 <str2Tree+0x62>
mov    %rax,%r13
mov    $0x8,%ebp
xor    %r15d,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r15,%rbx
add    $0x1,%r15
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <realloc@plt>
mov    %rax,%r12
mov    %r13,(%rax,%rbx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%r13
add    $0x8,%ebp
test   %rax,%rax
jne    1160 <str2Tree+0x30>
jmp    1198 <str2Tree+0x68>
xor    %eax,%eax
ret
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %r15d,%edi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <argv2Tree@plt>

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

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define %struct.TreeNode* @str2Tree(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %24, label %4
4: ; preds = %2
%5 = tail call i8* @strtok(i8* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %11, %7 ], [ 0, %4 ]
%9 = phi i8* [ %16, %7 ], [ %5, %4 ]
%10 = phi i8** [ %14, %7 ], [ null, %4 ]
%11 = add nuw i64 %8, 1
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 3
%14 = tail call i8** @realloc(i8** %10, i32 %13)
%15 = getelementptr inbounds i8*, i8** %14, i64 %8
store i8* %9, i8** %15
%16 = tail call i8* @strtok(i8* null, i8* %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %7
18: ; preds = %7
%19 = trunc i64 %11 to i32
br label %20
20: ; preds = %18, %4
%21 = phi i32 [ 0, %4 ], [ %19, %18 ]
%22 = phi i8** [ null, %4 ], [ %14, %18 ]
%23 = tail call %struct.TreeNode* @argv2Tree(i32 %21, i8** %22)
br label %24
24: ; preds = %2, %20
%25 = phi %struct.TreeNode* [ %23, %20 ], [ null, %2 ]
ret %struct.TreeNode* %25
}