#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 **calloc(int, int);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *strtok(char *, char *);
char **read_formats(char *fmts) {
  char **array = calloc(5, sizeof(char *));
  if (array != NULL) {
    int i = 0;
    char *text = strdup(fmts);
    if (text != NULL) {
      char *token = strtok(text, ",");
      while (token != NULL) {
        array[i++] = strdup(token);
        token = strtok(NULL, "/");
      }
      free(text);
    }
  }
  return array;
}


x86 assembly (clang, -O0):
<read_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x5,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f1 <read_formats+0xb1>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ec <read_formats+0xac>
mov    -0x20(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e3 <read_formats+0xa3>
mov    -0x28(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    119d <read_formats+0x5d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11f1 <read_formats+0xb1>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_formats>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x5,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11b6 <read_formats+0x76>
mov    %rbx,%rdi
call   1060 <strdup@plt>
test   %rax,%rax
je     11b6 <read_formats+0x76>
mov    %rax,%r14
lea    0xe87(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11ae <read_formats+0x6e>
lea    0xe75(%rip),%r12
mov    %r15,%rbx
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,(%rbx)
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1190 <read_formats+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c"/\00"
define noalias i8** @read_formats(i8* nocapture %0) {
%2 = tail call i8** @calloc(i32 5, i32 8)
%3 = icmp eq i8** %2, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %14, %10 ], [ 0, %7 ]
%12 = phi i8* [ %16, %10 ], [ %8, %7 ]
%13 = tail call i8* @strdup(i8* %12)
%14 = add nuw i64 %11, 1
%15 = getelementptr inbounds i8*, i8** %2, i64 %11
store i8* %13, i8** %15
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %10
18: ; preds = %10, %7
%19 = tail call i32 @free(i8* %5)
br label %20
20: ; preds = %4, %18, %1
ret i8** %2
}