#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*/ dgr_set(char *, char const *, int);
int /*<<< orphan*/ memcpy(int *, char const *, int);
void dgr_unserialize(int size, const char *serialized) {
  const char *ptr = serialized;
  while (ptr < serialized + size) {
    int c = 0;
    char name[1024];
    while (*ptr != 0) {
      name[c++] = *ptr;
      ptr++;
    }
    name[c++] = '\0';
    ptr++;
    int size = 0;
    memcpy(&size, ptr, sizeof(int));
    ptr += sizeof(int);
    dgr_set(name, ptr, size);
    ptr += size;
  }
}


x86 assembly (clang, -O0):
<dgr_unserialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x4(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    120f <dgr_unserialize+0xef>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1194 <dgr_unserialize+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %cl,-0x420(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1159 <dgr_unserialize+0x39>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x424(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1040 <dgr_set@plt>
mov    -0x424(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    113a <dgr_unserialize+0x1a>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dgr_unserialize>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
test   %edi,%edi
jle    11b6 <dgr_unserialize+0x96>
mov    %rsi,%rbx
movslq %edi,%r12
add    %rsi,%r12
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r15
jmp    1191 <dgr_unserialize+0x71>
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x1(%rbx),%rsi
movl   $0x0,0xc(%rsp)
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
lea    0x5(%rbx),%rsi
mov    0xc(%rsp),%edx
mov    %r15,%rdi
call   1040 <dgr_set@plt>
movslq 0xc(%rsp),%rax
add    %rax,%rbx
add    $0x5,%rbx
cmp    %r12,%rbx
jae    11b6 <dgr_unserialize+0x96>
mov    (%rbx),%cl
xor    %eax,%eax
test   %cl,%cl
je     1150 <dgr_unserialize+0x30>
nopl   0x0(%rax)
mov    %cl,0x10(%rsp,%rax,1)
movzbl 0x1(%rbx,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    11a0 <dgr_unserialize+0x80>
add    %rax,%rbx
jmp    1150 <dgr_unserialize+0x30>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @dgr_unserialize(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = sext i32 %0 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %38
8: ; preds = %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
br label %11
11: ; preds = %8, %24
%12 = phi i8* [ %1, %8 ], [ %36, %24 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %11, %15
%16 = phi i64 [ %19, %15 ], [ 0, %11 ]
%17 = phi i8 [ %22, %15 ], [ %13, %11 ]
%18 = phi i8* [ %21, %15 ], [ %12, %11 ]
%19 = add nuw i64 %16, 1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %16
store i8 %17, i8* %20
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %15, %11
%25 = phi i8* [ %12, %11 ], [ %21, %15 ]
%26 = phi i64 [ 0, %11 ], [ %19, %15 ]
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds i8, i8* %25, i64 1
store i32 0, i32* %4
%30 = call i32 @memcpy(i32* %4, i8* %29, i32 4)
%31 = getelementptr inbounds i8, i8* %25, i64 5
%32 = load i32, i32* %4
%33 = call i32 @dgr_set(i8* %9, i8* %31, i32 %32)
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %31, i64 %35
%37 = icmp ult i8* %36, %6
br i1 %37, label %11, label %38
38: ; preds = %24, %2
ret void
}