#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 asn1_get_length_der(unsigned char const *, int, int *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int asn1_get_octet_der(const unsigned char *der, int der_len, int *ret_len,
                       unsigned char *str, int str_size, int *str_len) {
  int len_len;
  if (der_len <= 0)
    return 6;
  *str_len = asn1_get_length_der(der, der_len, &len_len);
  if (*str_len < 0)
    return 4;
  *ret_len = *str_len + len_len;
  if (str_size >= *str_len)
    memcpy(str, der + len_len, *str_len);
  else {
    return 12;
  }
  return 0;
}


x86 assembly (clang, -O0):
<asn1_get_octet_der>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1155 <asn1_get_octet_der+0x35>
movl   $0x6,-0x4(%rbp)
jmp    11d6 <asn1_get_octet_der+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x3c(%rbp),%rdx
call   1040 <asn1_get_length_der@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1186 <asn1_get_octet_der+0x66>
movl   $0x4,-0x4(%rbp)
jmp    11d6 <asn1_get_octet_der+0xb6>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
add    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%eax
jl     11c3 <asn1_get_octet_der+0xa3>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
jmp    11cf <asn1_get_octet_der+0xaf>
movl   $0xc,-0x4(%rbp)
jmp    11d6 <asn1_get_octet_der+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_get_octet_der>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    117a <asn1_get_octet_der+0x5a>
mov    %r9,%rbp
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
call   1040 <asn1_get_length_der@plt>
mov    %eax,0x0(%rbp)
test   %eax,%eax
js     1181 <asn1_get_octet_der+0x61>
movslq 0xc(%rsp),%rcx
add    %ecx,%eax
mov    %eax,(%r12)
mov    0x0(%rbp),%edx
mov    $0xc,%eax
cmp    %r15d,%edx
jg     1186 <asn1_get_octet_der+0x66>
add    %rcx,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
xor    %eax,%eax
jmp    1186 <asn1_get_octet_der+0x66>
mov    $0x6,%eax
jmp    1186 <asn1_get_octet_der+0x66>
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @asn1_get_octet_der(i8* %0, i32 %1, i32* nocapture writeonly %2, i8* %3, i32 %4, i32* nocapture %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = icmp slt i32 %1, 1
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = call i32 @asn1_get_length_der(i8* %0, i32 %1, i32* %7)
store i32 %11, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = load i32, i32* %7
%15 = add nsw i32 %14, %11
store i32 %15, i32* %2
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, %4
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = call i32 @memcpy(i8* %3, i8* %20, i32 %16)
br label %22
22: ; preds = %13, %10, %6, %18
%23 = phi i32 [ 0, %18 ], [ 6, %6 ], [ 4, %10 ], [ 12, %13 ]
ret i32 %23
}