#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 */
struct stree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ stree_delete_tree(struct stree *);
struct stree *stree_new_tree(int, int);
int stree_ukkonen_add_string(struct stree *, char *, int, int);
int strlen(char *);
struct stree *stree_create_from_char(char **strings, int nstrings) {
  int i, len;
  char *str;
  struct stree *tree;
  if (!(tree = stree_new_tree(nstrings, 4)))
    return NULL;
  for (i = 0; i < nstrings; ++i) {
    len = strlen(strings[i]);
    str = strings[i];
    if (stree_ukkonen_add_string(tree, str, len, i + 1) < 1) {
      stree_delete_tree(tree);
      return NULL;
    }
  }
  return tree;
}


x86 assembly (clang, -O0):
<stree_create_from_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1030 <stree_new_tree@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1177 <stree_create_from_char+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11fe <stree_create_from_char+0xbe>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f6 <stree_create_from_char+0xb6>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
call   1050 <stree_ukkonen_add_string@plt>
cmp    $0x1,%eax
jge    11e3 <stree_create_from_char+0xa3>
mov    -0x30(%rbp),%rdi
call   1060 <stree_delete_tree@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fe <stree_create_from_char+0xbe>
jmp    11e8 <stree_create_from_char+0xa8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117e <stree_create_from_char+0x3e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stree_create_from_char>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%edi
mov    $0x4,%esi
call   1030 <stree_new_tree@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     119e <stree_create_from_char+0x5e>
mov    %rax,%r14
test   %r15d,%r15d
cmovle %ebx,%r15d
nopl   0x0(%rax,%rax,1)
cmp    %rbx,%r15
je     11a1 <stree_create_from_char+0x61>
mov    (%r12,%rbx,8),%rdi
call   1040 <strlen@plt>
mov    (%r12,%rbx,8),%rsi
add    $0x1,%rbx
mov    %r14,%rdi
mov    %eax,%edx
mov    %ebx,%ecx
call   1050 <stree_ukkonen_add_string@plt>
test   %eax,%eax
jg     1170 <stree_create_from_char+0x30>
mov    %r14,%rdi
call   1060 <stree_delete_tree@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stree = type { i32 }
define %struct.stree* @stree_create_from_char(i8** %0, i32 %1) {
%3 = alloca %struct.stree*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.stree*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = call %struct.stree* @stree_new_tree(i32 %10, i32 4)
store %struct.stree* %11, %struct.stree** %9
%12 = icmp ne %struct.stree* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store %struct.stree* null, %struct.stree** %3
br label %47
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %42, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %45
19: ; preds = %15
%20 = load i8**, i8*** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %8
%31 = load %struct.stree*, %struct.stree** %9
%32 = load i8*, i8** %8
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
%36 = call i32 @stree_ukkonen_add_string(%struct.stree* %31, i8* %32, i32 %33, i32 %35)
%37 = icmp slt i32 %36, 1
br i1 %37, label %38, label %41
38: ; preds = %19
%39 = load %struct.stree*, %struct.stree** %9
%40 = call i32 @stree_delete_tree(%struct.stree* %39)
store %struct.stree* null, %struct.stree** %3
br label %47
41: ; preds = %19
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %15
45: ; preds = %15
%46 = load %struct.stree*, %struct.stree** %9
store %struct.stree* %46, %struct.stree** %3
br label %47
47: ; preds = %45, %38, %13
%48 = load %struct.stree*, %struct.stree** %3
ret %struct.stree* %48
}

LLVM IR (-O2):
%struct.stree = type { i32 }
define %struct.stree* @stree_create_from_char(i8** nocapture %0, i32 %1) {
%3 = tail call %struct.stree* @stree_new_tree(i32 %1, i32 4)
%4 = icmp eq %struct.stree* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %11
%9 = phi i64 [ 0, %5 ], [ %16, %11 ]
%10 = icmp eq i64 %9, %7
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8*, i8** %0, i64 %9
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %13)
%15 = load i8*, i8** %12
%16 = add nuw nsw i64 %9, 1
%17 = trunc i64 %16 to i32
%18 = tail call i32 @stree_ukkonen_add_string(%struct.stree* %3, i8* %15, i32 %14, i32 %17)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %8
20: ; preds = %11
%21 = tail call i32 @stree_delete_tree(%struct.stree* %3)
br label %22
22: ; preds = %8, %2, %20
%23 = phi %struct.stree* [ null, %20 ], [ null, %2 ], [ %3, %8 ]
ret %struct.stree* %23
}