#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 */
long _asn1_get_indefinite_length_string(unsigned char const *, int *);
int asn1_get_length_der(unsigned char const *, int, int *);
signed long asn1_get_length_ber(const unsigned char *ber, int ber_len,
                                int *len) {
  int ret;
  long err;
  ret = asn1_get_length_der(ber, ber_len, len);
  if (ret == -1) {
    ret = ber_len;
    err = _asn1_get_indefinite_length_string(ber + 1, &ret);
    if (err != 0)
      return -3;
  }
  return ret;
}


x86 assembly (clang, -O0):
<asn1_get_length_ber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <asn1_get_length_der@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1188 <asn1_get_length_ber+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    -0x24(%rbp),%rsi
call   1030 <_asn1_get_indefinite_length_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1183 <asn1_get_length_ber+0x63>
movq   $0xfffffffffffffffd,-0x8(%rbp)
ff
jmp    1190 <asn1_get_length_ber+0x70>
jmp    1188 <asn1_get_length_ber+0x68>
movslq -0x24(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_get_length_ber>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <asn1_get_length_der@plt>
cmp    $0xffffffff,%eax
je     1136 <asn1_get_length_ber+0x16>
cltq
jmp    115a <asn1_get_length_ber+0x3a>
mov    %ebp,0x4(%rsp)
add    $0x1,%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <_asn1_get_indefinite_length_string@plt>
mov    %rax,%rcx
mov    $0xfffffffffffffffd,%rax
test   %rcx,%rcx
je     1161 <asn1_get_length_ber+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x4(%rsp),%eax
jmp    1132 <asn1_get_length_ber+0x12>

LLVM IR (-O0):
define i64 @asn1_get_length_ber(i8* %0, i32 %1, i32* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = load i32*, i32** %7
%13 = call i32 @asn1_get_length_der(i8* %10, i32 %11, i32* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %25
16: ; preds = %3
%17 = load i32, i32* %6
store i32 %17, i32* %8
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i64 @_asn1_get_indefinite_length_string(i8* %19, i32* %8)
store i64 %20, i64* %9
%21 = load i64, i64* %9
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i64 -3, i64* %4
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24, %3
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
store i64 %27, i64* %4
br label %28
28: ; preds = %25, %23
%29 = load i64, i64* %4
ret i64 %29
}

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