#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
char *strtok(char *, char *);
void str_split(char *cmd, const char token_delimiter, char **fields) {
  int id_tok = 0;
  char delim[] = {token_delimiter, '\0'};
  char *token = strtok(cmd, delim);
  while (token != NULL) {
    char c = *token;
    fields[id_tok] = strdup(token);
    token = strtok(0, delim);
    id_tok++;
    if (c == '$') {
      break;
    }
  }
  fields[id_tok] = malloc(sizeof(char) * 4096);
  sprintf(fields[id_tok], "* Mittente: %s *\n", fields[id_tok - 1]);
  while (token != NULL) {
    strcat(fields[id_tok], token);
    strcat(fields[id_tok], " ");
    token = strtok(0, delim);
  }
  fields[++id_tok] = NULL;
}


x86 assembly (clang, -O0):
<str_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e5 <str_split+0x95>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
lea    -0x1e(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x24,%eax
jne    11e0 <str_split+0x90>
jmp    11e5 <str_split+0x95>
jmp    1188 <str_split+0x38>
mov    $0x1000,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdde(%rip),%rsi
call   1060 <sprintf@plt>
cmpq   $0x0,-0x28(%rbp)
je     1275 <str_split+0x125>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdb8(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x1e(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1227 <str_split+0xd7>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %sil,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x6(%rsp),%r15
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     11ad <str_split+0x5d>
movzbl (%rbx),%ebp
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14,%r12,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
add    $0x1,%r12
cmp    $0x24,%bpl
jne    1180 <str_split+0x30>
jmp    11af <str_split+0x5f>
xor    %ebx,%ebx
mov    $0x1000,%edi
call   1030 <malloc@plt>
mov    %r12,%r13
shl    $0x20,%r13
mov    %r13,%rcx
sar    $0x1d,%rcx
mov    %rax,(%r14,%rcx,1)
movabs $0xffffffff00000000,%rcx
ff ff ff
add    %r13,%rcx
sar    $0x1d,%rcx
mov    (%r14,%rcx,1),%rdx
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
call   1060 <sprintf@plt>
test   %rbx,%rbx
je     123a <str_split+0xea>
movslq %r12d,%rbp
lea    0xe14(%rip),%r15
lea    0x6(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbp,8),%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    (%r14,%rbp,8),%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <str_split+0xc0>
movabs $0x100000000,%rax
add    %rax,%r13
sar    $0x1d,%r13
movq   $0x0,(%r14,%r13,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"* Mittente: %s *\0A\00"
@.str.1 = [2 x i8] c" \00"
define void @str_split(i8* %0, i8 signext %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8**
%7 = alloca i32
%8 = alloca [2 x i8]
%9 = alloca i8*
%10 = alloca i8
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8** %2, i8*** %6
store i32 0, i32* %7
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%12 = load i8, i8* %5
store i8 %12, i8* %11
%13 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %13
%14 = load i8*, i8** %4
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%16 = call i8* @strtok(i8* %14, i8* %15)
store i8* %16, i8** %9
br label %17
17: ; preds = %37, %3
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %38
20: ; preds = %17
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
store i8 %22, i8* %10
%23 = load i8*, i8** %9
%24 = call i8* @strdup(i8* %23)
%25 = load i8**, i8*** %6
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
store i8* %24, i8** %28
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%30 = call i8* @strtok(i8* null, i8* %29)
store i8* %30, i8** %9
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = load i8, i8* %10
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 36
br i1 %35, label %36, label %37
36: ; preds = %20
br label %38
37: ; preds = %20
br label %17
38: ; preds = %36, %17
%39 = call i8* @malloc(i32 4096)
%40 = load i8**, i8*** %6
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
%44 = load i8**, i8*** %6
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %6
%50 = load i32, i32* %7
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %59, %38
%57 = load i8*, i8** %9
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %75
59: ; preds = %56
%60 = load i8**, i8*** %6
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = load i8*, i8** %9
%66 = call i32 @strcat(i8* %64, i8* %65)
%67 = load i8**, i8*** %6
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%73 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%74 = call i8* @strtok(i8* null, i8* %73)
store i8* %74, i8** %9
br label %56
75: ; preds = %56
%76 = load i8**, i8*** %6
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %76, i64 %79
store i8* null, i8** %80
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"* Mittente: %s *\0A\00"
@.str.1 = [2 x i8] c" \00"
define void @str_split(i8* %0, i8 signext %1, i8** nocapture %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %1, i8* %5
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %6
%7 = call i8* @strtok(i8* %0, i8* %5)
br label %8
8: ; preds = %12, %3
%9 = phi i64 [ %17, %12 ], [ 0, %3 ]
%10 = phi i8* [ %16, %12 ], [ %7, %3 ]
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %8
%13 = load i8, i8* %10
%14 = tail call i8* @strdup(i8* %10)
%15 = getelementptr inbounds i8*, i8** %2, i64 %9
store i8* %14, i8** %15
%16 = call i8* @strtok(i8* null, i8* %5)
%17 = add nuw i64 %9, 1
%18 = icmp eq i8 %13, 36
br i1 %18, label %19, label %8
19: ; preds = %12, %8
%20 = phi i8* [ %16, %12 ], [ null, %8 ]
%21 = phi i64 [ %17, %12 ], [ %9, %8 ]
%22 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%23 = shl i64 %21, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8*, i8** %2, i64 %24
store i8* %22, i8** %25
%26 = shl i64 %21, 32
%27 = add i64 %26, -4294967296
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds i8*, i8** %2, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = icmp eq i8* %20, null
br i1 %32, label %41, label %33
33: ; preds = %19, %33
%34 = phi i8* [ %39, %33 ], [ %20, %19 ]
%35 = load i8*, i8** %25
%36 = tail call i32 @strcat(i8* %35, i8* %34)
%37 = load i8*, i8** %25
%38 = tail call i32 @strcat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = call i8* @strtok(i8* null, i8* %5)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %33
41: ; preds = %33, %19
%42 = shl i64 %21, 32
%43 = add i64 %42, 4294967296
%44 = ashr exact i64 %43, 32
%45 = getelementptr inbounds i8*, i8** %2, i64 %44
store i8* null, i8** %45
ret void
}