#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *rindex(char *, char);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char **ut_SplitMessage(char *mensaje, int *nsubmsgs, unsigned int maxlong) {
  char *running;
  char *aux;
  char *aux2;
  char **submsgs;
  char *buffer = (char *)malloc(strlen(mensaje) * 2);
  int i = 0;
  submsgs = (char **)malloc(50 * sizeof(char *));
  running = strdup(mensaje);
  aux2 = strdup(mensaje);
  while (strlen(aux2) > maxlong) {
    memset(buffer, 0, strlen(mensaje) * 2);
    running[maxlong] = '\0';
    aux = rindex(running, ' ');
    if (aux != NULL)
      strncpy(buffer, running, strlen(running) - strlen(aux));
    else
      strcpy(buffer, running);
    submsgs[i] = (char *)malloc(strlen(buffer) + 1);
    strcpy(submsgs[i], buffer);
    i++;
    aux2 += strlen(buffer) + 1;
    sprintf(running, "%s", aux2);
  }
  if (strlen(aux2) > 0) {
    submsgs[i] = (char *)malloc(strlen(aux2) + 1);
    strcpy(submsgs[i], aux2);
    i++;
  }
  (*nsubmsgs) = i;
  free(buffer);
  return submsgs;
}


x86 assembly (clang, -O0):
<ut_SplitMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x190,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cmp    -0x14(%rbp),%eax
jbe    1302 <ut_SplitMessage+0x172>
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
shl    $0x1,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1090 <rindex@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1280 <ut_SplitMessage+0xf0>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
sub    %eax,%edx
call   1040 <strncpy@plt>
jmp    128d <ut_SplitMessage+0xfd>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd08(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    11e9 <ut_SplitMessage+0x59>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jle    1354 <ut_SplitMessage+0x1c4>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_SplitMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r13d
mov    %rsi,0x20(%rsp)
mov    %rdi,%r14
call   1060 <strlen@plt>
lea    (%rax,%rax,1),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    $0x190,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %r14,%rdi
call   10a0 <strdup@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
xor    %ebp,%ebp
cmp    %r13d,%eax
jbe    12d2 <ut_SplitMessage+0x152>
mov    %r13d,%eax
mov    %rax,0x30(%rsp)
xor    %ebp,%ebp
mov    %r13d,0x1c(%rsp)
mov    %r14,0x28(%rsp)
mov    0x8(%rsp),%r12
jmp    1268 <ut_SplitMessage+0xe8>
xchg   %ax,%ax
mov    %r14,%rdi
mov    0x8(%rsp),%rsi
call   1050 <strcpy@plt>
mov    %r14,%r15
mov    0x28(%rsp),%r14
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx,%rbp,8)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
add    $0x1,%rbp
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    %r13d,%eax
jbe    12d2 <ut_SplitMessage+0x152>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rax,1),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x8(%rsp),%rdi
mov    0x30(%rsp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    $0x20,%esi
call   1090 <rindex@plt>
mov    %r15,%r14
test   %rax,%rax
je     1200 <ut_SplitMessage+0x80>
mov    %rax,%r15
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1060 <strlen@plt>
sub    %eax,%r13d
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    0x1c(%rsp),%r13d
call   1040 <strncpy@plt>
jmp    120d <ut_SplitMessage+0x8d>
mov    0x20(%rsp),%r14
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    130c <ut_SplitMessage+0x18c>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %ebp,%ecx
mov    0x10(%rsp),%rdx
mov    %rax,(%rdx,%rcx,8)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
add    $0x1,%ebp
mov    %ebp,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8** @ut_SplitMessage(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = mul nsw i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %11
store i32 0, i32* %12
%18 = call i64 @malloc(i32 400)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %10
%20 = load i8*, i8** %4
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %4
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %9
br label %24
24: ; preds = %56, %3
%25 = load i8*, i8** %9
%26 = call i32 @strlen(i8* %25)
%27 = load i32, i32* %6
%28 = icmp ugt i32 %26, %27
br i1 %28, label %29, label %84
29: ; preds = %24
%30 = load i8*, i8** %11
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = mul nsw i32 %32, 2
%34 = call i32 @memset(i8* %30, i32 0, i32 %33)
%35 = load i8*, i8** %7
%36 = load i32, i32* %6
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %7
%40 = call i8* @rindex(i8* %39, i8 signext 32)
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %52
43: ; preds = %29
%44 = load i8*, i8** %11
%45 = load i8*, i8** %7
%46 = load i8*, i8** %7
%47 = call i32 @strlen(i8* %46)
%48 = load i8*, i8** %8
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 %47, %49
%51 = call i32 @strncpy(i8* %44, i8* %45, i32 %50)
br label %56
52: ; preds = %29
%53 = load i8*, i8** %11
%54 = load i8*, i8** %7
%55 = call i32 @strcpy(i8* %53, i8* %54)
br label %56
56: ; preds = %52, %43
%57 = load i8*, i8** %11
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %58, 1
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i8*
%62 = load i8**, i8*** %10
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
store i8* %61, i8** %65
%66 = load i8**, i8*** %10
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = load i8*, i8** %11
%72 = call i32 @strcpy(i8* %70, i8* %71)
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
%75 = load i8*, i8** %11
%76 = call i32 @strlen(i8* %75)
%77 = add nsw i32 %76, 1
%78 = load i8*, i8** %9
%79 = sext i32 %77 to i64
%80 = getelementptr inbounds i8, i8* %78, i64 %79
store i8* %80, i8** %9
%81 = load i8*, i8** %7
%82 = load i8*, i8** %9
%83 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %82)
br label %24
84: ; preds = %24
%85 = load i8*, i8** %9
%86 = call i32 @strlen(i8* %85)
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %107
88: ; preds = %84
%89 = load i8*, i8** %9
%90 = call i32 @strlen(i8* %89)
%91 = add nsw i32 %90, 1
%92 = call i64 @malloc(i32 %91)
%93 = inttoptr i64 %92 to i8*
%94 = load i8**, i8*** %10
%95 = load i32, i32* %12
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
store i8* %93, i8** %97
%98 = load i8**, i8*** %10
%99 = load i32, i32* %12
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8*, i8** %98, i64 %100
%102 = load i8*, i8** %101
%103 = load i8*, i8** %9
%104 = call i32 @strcpy(i8* %102, i8* %103)
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %107
107: ; preds = %88, %84
%108 = load i32, i32* %12
%109 = load i32*, i32** %5
store i32 %108, i32* %109
%110 = load i8*, i8** %11
%111 = call i32 @free(i8* %110)
%112 = load i8**, i8*** %10
ret i8** %112
}

LLVM IR (-O2):
define i8** @ut_SplitMessage(i8* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = shl nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @malloc(i32 400)
%9 = inttoptr i64 %8 to i8**
%10 = tail call i8* @strdup(i8* %0)
%11 = tail call i8* @strdup(i8* %0)
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp ugt i32 %12, %2
br i1 %13, label %14, label %49
14: ; preds = %3
%15 = zext i32 %2 to i64
%16 = getelementptr inbounds i8, i8* %10, i64 %15
br label %17
17: ; preds = %14, %32
%18 = phi i64 [ 0, %14 ], [ %39, %32 ]
%19 = phi i8* [ %11, %14 ], [ %43, %32 ]
%20 = tail call i32 @strlen(i8* %0)
%21 = shl nsw i32 %20, 1
%22 = tail call i32 @memset(i8* %7, i32 0, i32 %21)
store i8 0, i8* %16
%23 = tail call i8* @rindex(i8* %10, i8 signext 32)
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %17
%26 = tail call i32 @strlen(i8* %10)
%27 = tail call i32 @strlen(i8* %23)
%28 = sub nsw i32 %26, %27
%29 = tail call i32 @strncpy(i8* %7, i8* %10, i32 %28)
br label %32
30: ; preds = %17
%31 = tail call i32 @strcpy(i8* %7, i8* %10)
br label %32
32: ; preds = %30, %25
%33 = tail call i32 @strlen(i8* %7)
%34 = add nsw i32 %33, 1
%35 = tail call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i8*
%37 = getelementptr inbounds i8*, i8** %9, i64 %18
store i8* %36, i8** %37
%38 = tail call i32 @strcpy(i8* %36, i8* %7)
%39 = add nuw i64 %18, 1
%40 = tail call i32 @strlen(i8* %7)
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %19, i64 %42
%44 = tail call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %10, i8* %43)
%45 = tail call i32 @strlen(i8* %43)
%46 = icmp ugt i32 %45, %2
br i1 %46, label %17, label %47
47: ; preds = %32
%48 = trunc i64 %39 to i32
br label %49
49: ; preds = %47, %3
%50 = phi i8* [ %11, %3 ], [ %43, %47 ]
%51 = phi i32 [ 0, %3 ], [ %48, %47 ]
%52 = tail call i32 @strlen(i8* %50)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %49
%55 = tail call i32 @strlen(i8* %50)
%56 = add nsw i32 %55, 1
%57 = tail call i64 @malloc(i32 %56)
%58 = inttoptr i64 %57 to i8*
%59 = zext i32 %51 to i64
%60 = getelementptr inbounds i8*, i8** %9, i64 %59
store i8* %58, i8** %60
%61 = tail call i32 @strcpy(i8* %58, i8* %50)
%62 = add nuw nsw i32 %51, 1
br label %63
63: ; preds = %54, %49
%64 = phi i32 [ %62, %54 ], [ %51, %49 ]
store i32 %64, i32* %1
%65 = tail call i32 @free(i8* %7)
ret i8** %9
}