#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 */
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
char *bson_find_field(char *, char *, int);
char *strdup(char *);
int bson_find_field_as_stringl(char *buffer, char *field, char **data,
                               int32_t *length, int duplicate) {
  char *tmp = bson_find_field(buffer, field, 0x02);
  if (tmp) {
    *length = ((int32_t *)tmp)[0];
    *data = duplicate ? strdup(tmp + 4) : tmp + 4;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bson_find_field_as_stringl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <bson_find_field@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11ac <bson_find_field_as_stringl+0x8c>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x2c(%rbp)
je     1189 <bson_find_field_as_stringl+0x69>
mov    -0x38(%rbp),%rdi
add    $0x4,%rdi
call   1040 <strdup@plt>
mov    %rax,-0x40(%rbp)
jmp    1195 <bson_find_field_as_stringl+0x75>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b3 <bson_find_field_as_stringl+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bson_find_field_as_stringl>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    $0x2,%edx
call   1030 <bson_find_field@plt>
test   %rax,%rax
je     115a <bson_find_field_as_stringl+0x3a>
mov    (%rax),%ecx
mov    %ecx,(%rbx)
add    $0x4,%rax
test   %ebp,%ebp
je     1150 <bson_find_field_as_stringl+0x30>
mov    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
jmp    115c <bson_find_field_as_stringl+0x3c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bson_find_field_as_stringl(i8* %0, i8* %1, i8** %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = call i8* @bson_find_field(i8* %13, i8* %14, i32 2)
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %36
18: ; preds = %5
%19 = load i8*, i8** %12
%20 = bitcast i8* %19 to i32*
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
%23 = load i32*, i32** %10
store i32 %22, i32* %23
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = load i8*, i8** %12
%28 = getelementptr inbounds i8, i8* %27, i64 4
%29 = call i8* @strdup(i8* %28)
br label %33
30: ; preds = %18
%31 = load i8*, i8** %12
%32 = getelementptr inbounds i8, i8* %31, i64 4
br label %33
33: ; preds = %30, %26
%34 = phi i8* [ %29, %26 ], [ %32, %30 ]
%35 = load i8**, i8*** %9
store i8* %34, i8** %35
store i32 1, i32* %6
br label %37
36: ; preds = %5
store i32 0, i32* %6
br label %37
37: ; preds = %36, %33
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
define i32 @bson_find_field_as_stringl(i8* %0, i8* %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3, i32 %4) {
%6 = tail call i8* @bson_find_field(i8* %0, i8* %1, i32 2)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = bitcast i8* %6 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %3
%11 = icmp eq i32 %4, 0
%12 = getelementptr inbounds i8, i8* %6, i64 4
br i1 %11, label %15, label %13
13: ; preds = %8
%14 = tail call i8* @strdup(i8* %12)
br label %15
15: ; preds = %8, %13
%16 = phi i8* [ %14, %13 ], [ %12, %8 ]
store i8* %16, i8** %2
br label %17
17: ; preds = %5, %15
%18 = phi i32 [ 1, %15 ], [ 0, %5 ]
ret i32 %18
}