#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 *engine_id_alloc(char const *, char *);
char *strchr(char const *, char);
char *strdup(char const *);
void engine_id_split(const char *id, char **id_chapter, char **id_scene,
                     char **id_room, char **id_entity) {
  char *it1 = NULL, *it2 = NULL, *it3 = NULL;
  it1 = strchr(id, '.');
  if (!it1) {
    *id_chapter = strdup(id);
    return;
  }
  *id_chapter = engine_id_alloc(id, it1);
  it2 = strchr(it1 + 1, '.');
  if (!it2) {
    *id_scene = strdup(it1 + 1);
    return;
  }
  *id_scene = engine_id_alloc(it1 + 1, it2);
  it3 = strchr(it2 + 1, '.');
  if (!it3) {
    *id_room = strdup(it2 + 1);
    return;
  }
  *id_room = engine_id_alloc(it2 + 1, it3);
  *id_entity = strdup(it3 + 1);
}


x86 assembly (clang, -O0):
<engine_id_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1199 <engine_id_split+0x69>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1277 <engine_id_split+0x147>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ed <engine_id_split+0xbd>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1277 <engine_id_split+0x147>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x38(%rbp),%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1245 <engine_id_split+0x115>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    1277 <engine_id_split+0x147>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    -0x40(%rbp),%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<engine_id_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11cb <engine_id_split+0x9b>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,0x0(%r13)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d9 <engine_id_split+0xa9>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,(%r12)
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e7 <engine_id_split+0xb7>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <engine_id_alloc@plt>
mov    %rax,(%r15)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
jmp    11f2 <engine_id_split+0xc2>
mov    %rbp,%rdi
call   1050 <strdup@plt>
mov    %rax,0x0(%r13)
jmp    11f2 <engine_id_split+0xc2>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r12)
jmp    11f2 <engine_id_split+0xc2>
mov    %r13,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @engine_id_split(i8* %0, i8** %1, i8** %2, i8** %3, i8** %4) {
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
store i8** %4, i8*** %10
store i8* null, i8** %11
store i8* null, i8** %12
store i8* null, i8** %13
%14 = load i8*, i8** %6
%15 = call i8* @strchr(i8* %14, i8 signext 46)
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = icmp ne i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %5
%19 = load i8*, i8** %6
%20 = call i8* @strdup(i8* %19)
%21 = load i8**, i8*** %7
store i8* %20, i8** %21
br label %63
22: ; preds = %5
%23 = load i8*, i8** %6
%24 = load i8*, i8** %11
%25 = call i8* @engine_id_alloc(i8* %23, i8* %24)
%26 = load i8**, i8*** %7
store i8* %25, i8** %26
%27 = load i8*, i8** %11
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i8* @strchr(i8* %28, i8 signext 46)
store i8* %29, i8** %12
%30 = load i8*, i8** %12
%31 = icmp ne i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %22
%33 = load i8*, i8** %11
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i8* @strdup(i8* %34)
%36 = load i8**, i8*** %8
store i8* %35, i8** %36
br label %63
37: ; preds = %22
%38 = load i8*, i8** %11
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8*, i8** %12
%41 = call i8* @engine_id_alloc(i8* %39, i8* %40)
%42 = load i8**, i8*** %8
store i8* %41, i8** %42
%43 = load i8*, i8** %12
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i8* @strchr(i8* %44, i8 signext 46)
store i8* %45, i8** %13
%46 = load i8*, i8** %13
%47 = icmp ne i8* %46, null
br i1 %47, label %53, label %48
48: ; preds = %37
%49 = load i8*, i8** %12
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i8* @strdup(i8* %50)
%52 = load i8**, i8*** %9
store i8* %51, i8** %52
br label %63
53: ; preds = %37
%54 = load i8*, i8** %12
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8*, i8** %13
%57 = call i8* @engine_id_alloc(i8* %55, i8* %56)
%58 = load i8**, i8*** %9
store i8* %57, i8** %58
%59 = load i8*, i8** %13
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = call i8* @strdup(i8* %60)
%62 = load i8**, i8*** %10
store i8* %61, i8** %62
br label %63
63: ; preds = %53, %48, %32, %18
ret void
}

LLVM IR (-O2):
define void @engine_id_split(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3, i8** nocapture writeonly %4) {
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i8* @strdup(i8* %0)
store i8* %9, i8** %1
br label %28
10: ; preds = %5
%11 = tail call i8* @engine_id_alloc(i8* %0, i8* %6)
store i8* %11, i8** %1
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = tail call i8* @strchr(i8* %12, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i8* @strdup(i8* %12)
store i8* %16, i8** %2
br label %28
17: ; preds = %10
%18 = tail call i8* @engine_id_alloc(i8* %12, i8* %13)
store i8* %18, i8** %2
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = tail call i8* @strchr(i8* %19, i8 signext 46)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i8* @strdup(i8* %19)
store i8* %23, i8** %3
br label %28
24: ; preds = %17
%25 = tail call i8* @engine_id_alloc(i8* %19, i8* %20)
store i8* %25, i8** %3
%26 = getelementptr inbounds i8, i8* %20, i64 1
%27 = tail call i8* @strdup(i8* %26)
store i8* %27, i8** %4
br label %28
28: ; preds = %24, %22, %15, %8
ret void
}