#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 */
int /*<<< orphan*/ _debug(char *, char const *);
int db_add(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ parse_pair(char const *, char *, char *);
int /*<<< orphan*/ str_unescape(char *);
int strlen(char const *);
int db_unserialize(const char *buf) {
  int len = strlen(buf);
  char name[len + 10], value[len + 10];
  if (0)
    _debug("DEBUG: db_unserialize ('%s')\n", buf);
  if (parse_pair(buf, name, value))
    return db_add(str_unescape(name), str_unescape(value), 0);
  else
    return 0;
}


x86 assembly (clang, -O0):
<db_unserialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xa,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x48(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0xa,%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <parse_pair@plt>
cmp    $0x0,%rax
je     11e6 <db_unserialize+0xa6>
mov    -0x48(%rbp),%rdi
call   1040 <str_unescape@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x4c(%rbp)
call   1040 <str_unescape@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <db_add@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11f4 <db_unserialize+0xb4>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_unserialize>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
add    $0xa,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <parse_pair@plt>
test   %rax,%rax
je     11a3 <db_unserialize+0x63>
mov    %r14,%rdi
call   1040 <str_unescape@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <str_unescape@plt>
mov    %r14d,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <db_add@plt>
jmp    11a5 <db_unserialize+0x65>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @db_unserialize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 10
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i8, i64 %13
store i64 %13, i64* %6
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 10
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %7
%20 = load i8*, i8** %3
%21 = call i64 @parse_pair(i8* %20, i8* %15, i8* %19)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %1
%24 = call i32 @str_unescape(i8* %15)
%25 = call i32 @str_unescape(i8* %19)
%26 = call i32 @db_add(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %2
store i32 1, i32* %8
br label %28
27: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %8
br label %28
28: ; preds = %27, %23
%29 = load i8*, i8** %5
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @db_unserialize(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 10
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = call i64 @parse_pair(i8* %0, i8* %5, i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = call i32 @str_unescape(i8* %5)
%11 = call i32 @str_unescape(i8* %6)
%12 = call i32 @db_add(i32 %10, i32 %11, i32 0)
br label %13
13: ; preds = %1, %9
%14 = phi i32 [ %12, %9 ], [ 0, %1 ]
ret i32 %14
}