#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 *strchr(char *, int);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int split_block_id(char buffer[], int buflen, const char *block_id,
                   char **pBlockKey, char **pChainKey) {
  int dot = (int)'.';
  char *pc;
  buflen =
      (((int)strlen(block_id)) < (buflen)) ? ((int)strlen(block_id)) : (buflen);
  strncpy(buffer, block_id, buflen);
  buffer[buflen] = '\0';
  pc = strchr(buffer, dot);
  if (pc) {
    *pc = '\0';
    pc++;
    *pChainKey = pc;
  } else {
    *pChainKey = &buffer[buflen];
  }
  *pBlockKey = buffer;
  return (0);
}


x86 assembly (clang, -O0):
<split_block_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x2e,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jge    1175 <split_block_id+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
jmp    117b <split_block_id+0x4b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11db <split_block_id+0xab>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ed <split_block_id+0xbd>
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rax
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_block_id>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
cmovl  %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rbp
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1185 <split_block_id+0x55>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rbp
jmp    1188 <split_block_id+0x58>
add    %rbx,%rbp
mov    %rbp,(%r14)
mov    %rbx,(%r15)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_block_id(i8* %0, i32 %1, i8* %2, i8** %3, i8** %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
store i8** %4, i8*** %10
store i32 46, i32* %11
%13 = load i8*, i8** %8
%14 = call i64 @strlen(i8* %13)
%15 = trunc i64 %14 to i32
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = load i8*, i8** %8
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
br label %24
22: ; preds = %5
%23 = load i32, i32* %7
br label %24
24: ; preds = %22, %18
%25 = phi i32 [ %21, %18 ], [ %23, %22 ]
store i32 %25, i32* %7
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = call i32 @strncpy(i8* %26, i8* %27, i32 %28)
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = load i32, i32* %11
%36 = call i8* @strchr(i8* %34, i32 %35)
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %24
%40 = load i8*, i8** %12
store i8 0, i8* %40
%41 = load i8*, i8** %12
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %12
%43 = load i8*, i8** %12
%44 = load i8**, i8*** %10
store i8* %43, i8** %44
br label %51
45: ; preds = %24
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8**, i8*** %10
store i8* %49, i8** %50
br label %51
51: ; preds = %45, %39
%52 = load i8*, i8** %6
%53 = load i8**, i8*** %9
store i8* %52, i8** %53
ret i32 0
}

LLVM IR (-O2):
define i32 @split_block_id(i8* %0, i32 %1, i8* %2, i8** nocapture writeonly %3, i8** nocapture writeonly %4) {
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = trunc i64 %6 to i32
%8 = icmp slt i32 %7, %1
%9 = select i1 %8, i32 %7, i32 %1
%10 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %9)
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
%13 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %5
store i8 0, i8* %13
%16 = getelementptr inbounds i8, i8* %13, i64 1
br label %17
17: ; preds = %5, %15
%18 = phi i8* [ %16, %15 ], [ %12, %5 ]
store i8* %18, i8** %4
store i8* %0, i8** %3
ret i32 0
}