#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 */
struct AMCMutableBuffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _buffer_LOCK(struct AMCMutableBuffer *);
int /*<<< orphan*/ _buffer_UNLOCK(struct AMCMutableBuffer *);
size_t _buffer_get_len(struct AMCMutableBuffer *);
int /*<<< orphan*/ _buffer_is_correct_type(struct AMCMutableBuffer *);
size_t AMCMutableBuffer_GetLen(struct AMCMutableBuffer *buffer) {
  if ((0) == _buffer_is_correct_type(buffer)) {
    return 0;
  } else {
    size_t ret = 0;
    _buffer_LOCK(buffer);
    ret = _buffer_get_len(buffer);
    _buffer_UNLOCK(buffer);
    return ret;
  }
}


x86 assembly (clang, -O0):
<AMCMutableBuffer_GetLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_buffer_is_correct_type@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    116e <AMCMutableBuffer_GetLen+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    119d <AMCMutableBuffer_GetLen+0x5d>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_buffer_LOCK@plt>
mov    -0x10(%rbp),%rdi
call   1040 <_buffer_get_len@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <_buffer_UNLOCK@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AMCMutableBuffer_GetLen>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <_buffer_is_correct_type@plt>
test   %eax,%eax
je     1170 <AMCMutableBuffer_GetLen+0x30>
mov    %rbx,%rdi
call   1050 <_buffer_LOCK@plt>
mov    %rbx,%rdi
call   1040 <_buffer_get_len@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <_buffer_UNLOCK@plt>
mov    %r14,%rax
jmp    1172 <AMCMutableBuffer_GetLen+0x32>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.AMCMutableBuffer = type { i32 }
define i64 @AMCMutableBuffer_GetLen(%struct.AMCMutableBuffer* %0) {
%2 = alloca i64
%3 = alloca %struct.AMCMutableBuffer*
%4 = alloca i64
store %struct.AMCMutableBuffer* %0, %struct.AMCMutableBuffer** %3
%5 = load %struct.AMCMutableBuffer*, %struct.AMCMutableBuffer** %3
%6 = call i32 @_buffer_is_correct_type(%struct.AMCMutableBuffer* %5)
%7 = icmp eq i32 0, %6
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 0, i64* %2
br label %17
9: ; preds = %1
store i64 0, i64* %4
%10 = load %struct.AMCMutableBuffer*, %struct.AMCMutableBuffer** %3
%11 = call i32 @_buffer_LOCK(%struct.AMCMutableBuffer* %10)
%12 = load %struct.AMCMutableBuffer*, %struct.AMCMutableBuffer** %3
%13 = call i64 @_buffer_get_len(%struct.AMCMutableBuffer* %12)
store i64 %13, i64* %4
%14 = load %struct.AMCMutableBuffer*, %struct.AMCMutableBuffer** %3
%15 = call i32 @_buffer_UNLOCK(%struct.AMCMutableBuffer* %14)
%16 = load i64, i64* %4
store i64 %16, i64* %2
br label %17
17: ; preds = %9, %8
%18 = load i64, i64* %2
ret i64 %18
}

LLVM IR (-O2):
%struct.AMCMutableBuffer = type { i32 }
define i64 @AMCMutableBuffer_GetLen(%struct.AMCMutableBuffer* %0) {
%2 = tail call i32 @_buffer_is_correct_type(%struct.AMCMutableBuffer* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @_buffer_LOCK(%struct.AMCMutableBuffer* %0)
%6 = tail call i64 @_buffer_get_len(%struct.AMCMutableBuffer* %0)
%7 = tail call i32 @_buffer_UNLOCK(%struct.AMCMutableBuffer* %0)
br label %8
8: ; preds = %1, %4
%9 = phi i64 [ %6, %4 ], [ 0, %1 ]
ret i64 %9
}