#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 */
char *strtok(char *, char *);
int trocear_cadena(char *cadena, char *trozos[]) {
  int i = 1;
  if ((trozos[0] = strtok(cadena, " \n\t")) == NULL) {
    return 0;
  }
  while ((trozos[i] = strtok(NULL, " \n\t")) != NULL) {
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<trocear_cadena>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xece(%rip),%rsi
call   1030 <strtok@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1154 <trocear_cadena+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1193 <trocear_cadena+0x83>
jmp    1159 <trocear_cadena+0x49>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe9c(%rip),%rsi
call   1030 <strtok@plt>
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     118d <trocear_cadena+0x7d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <trocear_cadena+0x49>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trocear_cadena>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xee1(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,(%r14)
xor    %ebx,%ebx
test   %rax,%rax
je     1158 <trocear_cadena+0x48>
lea    0xecb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
mov    %rax,0x8(%r14,%rbx,8)
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <trocear_cadena+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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