#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 */
void *bson_get_current(char *, char **, int *);
char *bson_next(char *);
char *strdup(char *);
int bson_array_find_next_int32(char **buffer, char **field, int32_t *data) {
  char *read_field;
  int read_type;
  void *return_data;
  return_data = bson_get_current(*buffer, &read_field, &read_type);
  if (read_type == 0x10) {
    *data = ((int32_t *)return_data)[0];
    if (field) {
      *field = strdup(read_field);
    }
  }
  *buffer = bson_next(*buffer);
  return *buffer == NULL ? 0 : 1;
}


x86 assembly (clang, -O0):
<bson_array_find_next_int32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <bson_get_current@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x10,-0x24(%rbp)
jne    1195 <bson_array_find_next_int32+0x65>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1190 <bson_array_find_next_int32+0x60>
mov    -0x20(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1195 <bson_array_find_next_int32+0x65>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <bson_next@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bson_array_find_next_int32>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1040 <bson_get_current@plt>
cmpl   $0x10,0x4(%rsp)
jne    1172 <bson_array_find_next_int32+0x42>
mov    (%rax),%eax
mov    %eax,(%r15)
test   %r14,%r14
je     1172 <bson_array_find_next_int32+0x42>
mov    0x8(%rsp),%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
mov    (%rbx),%rdi
call   1030 <bson_next@plt>
mov    %rax,(%rbx)
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @bson_array_find_next_int32(i8** nocapture %0, i8** writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i8** %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = load i8*, i8** %0
%9 = call i8* @bson_get_current(i8* %8, i8** %4, i32* %5)
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 16
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = bitcast i8* %9 to i32*
%14 = load i32, i32* %13
store i32 %14, i32* %2
%15 = icmp eq i8** %1, null
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %1
br label %19
19: ; preds = %12, %16, %3
%20 = load i8*, i8** %0
%21 = call i8* @bson_next(i8* %20)
store i8* %21, i8** %0
%22 = icmp ne i8* %21, null
%23 = zext i1 %22 to i32
ret i32 %23
}