#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 */
unsigned int count_desktops(char const *);
int /*<<< orphan*/ free(char *);
void *malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strtok(char *, char *);
char **get_desktop_info(const char *bspwm_output) {
  unsigned int num_of_desktops = count_desktops(bspwm_output);
  char **desktop_info = malloc(sizeof(char *) * num_of_desktops);
  char *tmp = malloc(strlen(bspwm_output));
  strcpy(tmp, bspwm_output + 1);
  char *pch = strtok(tmp, ":");
  for (; pch != NULL && (pch[0] == 'M' || pch[0] == 'm');
       pch = strtok(NULL, ":"))
    ;
  for (unsigned int i = 0; i < num_of_desktops; ++i, pch = strtok(NULL, ":")) {
    desktop_info[i] = malloc(strlen(pch) + 1);
    strcpy(desktop_info[i], pch);
  }
  free(tmp);
  return desktop_info;
}


x86 assembly (clang, -O0):
<get_desktop_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <count_desktops@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
je     11fe <get_desktop_info+0x9e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x4d,%ecx
mov    %al,-0x2e(%rbp)
je     11f8 <get_desktop_info+0x98>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
sete   %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    120e <get_desktop_info+0xae>
jmp    122c <get_desktop_info+0xcc>
jmp    1213 <get_desktop_info+0xb3>
xor    %eax,%eax
mov    %eax,%edi
lea    0xde2(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11c3 <get_desktop_info+0x63>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1296 <get_desktop_info+0x136>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd78(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1233 <get_desktop_info+0xd3>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_desktop_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <count_desktops@plt>
mov    %eax,%r15d
lea    0x0(,%r15,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
add    $0x1,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe52(%rip),%rsi
mov    %r14,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     11f9 <get_desktop_info+0x99>
lea    0xe3e(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rax),%ecx
or     $0x20,%cl
mov    %rax,%rbx
cmp    $0x6d,%cl
jne    11f2 <get_desktop_info+0x92>
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    $0x0,%ebx
test   %rax,%rax
jne    11d0 <get_desktop_info+0x70>
test   %r15d,%r15d
jne    1200 <get_desktop_info+0xa0>
jmp    1245 <get_desktop_info+0xe5>
xor    %ebx,%ebx
test   %r15d,%r15d
je     1245 <get_desktop_info+0xe5>
mov    %r15d,%r13d
xor    %ebp,%ebp
lea    0xdf4(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%r12,%rbp,8)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
add    $0x1,%rbp
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
cmp    %rbp,%r13
jne    1210 <get_desktop_info+0xb0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define noalias i8** @get_desktop_info(i8* %0) {
%2 = tail call i32 @count_desktops(i8* %0)
%3 = shl i32 %2, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8* %4 to i8**
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* @malloc(i32 %6)
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = tail call i32 @strcpy(i8* %7, i8* %8)
%10 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %1, %15
%13 = phi i8* [ %16, %15 ], [ %10, %1 ]
%14 = load i8, i8* %13
switch i8 %14, label %18 [
i8 77, label %15
i8 109, label %15
]
15: ; preds = %12, %12
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %12
18: ; preds = %15, %12, %1
%19 = phi i8* [ null, %1 ], [ %13, %12 ], [ null, %15 ]
%20 = icmp eq i32 %2, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = zext i32 %2 to i64
br label %25
23: ; preds = %25, %18
%24 = tail call i32 @free(i8* %7)
ret i8** %5
25: ; preds = %21, %25
%26 = phi i64 [ 0, %21 ], [ %33, %25 ]
%27 = phi i8* [ %19, %21 ], [ %34, %25 ]
%28 = tail call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 1
%30 = tail call i8* @malloc(i32 %29)
%31 = getelementptr inbounds i8*, i8** %5, i64 %26
store i8* %30, i8** %31
%32 = tail call i32 @strcpy(i8* %30, i8* %27)
%33 = add nuw nsw i64 %26, 1
%34 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %33, %22
br i1 %35, label %23, label %25
}