#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_STRING;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, unsigned int);
int GetAsn1StringBytes(ASN1_STRING *asn1, unsigned char *pBuf, int cBuf) {
  if (!asn1 || cBuf < 0) {
    return 0;
  }
  int length = asn1->length;
  assert(length >= 0);
  if (length < 0) {
    return 0;
  }
  if (!pBuf || cBuf < length) {
    return -length;
  }
  memcpy(pBuf, asn1->data, (unsigned int)length);
  return 1;
}


x86 assembly (clang, -O0):
<GetAsn1StringBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1148 <GetAsn1StringBytes+0x28>
cmpl   $0x0,-0x1c(%rbp)
jge    1154 <GetAsn1StringBytes+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <GetAsn1StringBytes+0xa2>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x20(%rbp)
jge    1184 <GetAsn1StringBytes+0x64>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <GetAsn1StringBytes+0xa2>
cmpq   $0x0,-0x18(%rbp)
je     119b <GetAsn1StringBytes+0x7b>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11a8 <GetAsn1StringBytes+0x88>
xor    %eax,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <GetAsn1StringBytes+0xa2>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetAsn1StringBytes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     1173 <GetAsn1StringBytes+0x53>
mov    %edx,%r12d
test   %edx,%edx
js     1173 <GetAsn1StringBytes+0x53>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%ebp
mov    %ebp,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
test   %ebp,%ebp
js     1173 <GetAsn1StringBytes+0x53>
test   %r14,%r14
je     116e <GetAsn1StringBytes+0x4e>
cmp    %r12d,%ebp
ja     116e <GetAsn1StringBytes+0x4e>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    $0x1,%r15d
jmp    1173 <GetAsn1StringBytes+0x53>
neg    %ebp
mov    %ebp,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @GetAsn1StringBytes(%struct.TYPE_3__* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = icmp ne %struct.TYPE_3__* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store i32 0, i32* %4
br label %43
15: ; preds = %11
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp sge i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 0, i32* %4
br label %43
26: ; preds = %15
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29, %26
%34 = load i32, i32* %8
%35 = sub nsw i32 0, %34
store i32 %35, i32* %4
br label %43
36: ; preds = %29
%37 = load i8*, i8** %6
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = load i32, i32* %8
%42 = call i32 @memcpy(i8* %37, i32 %40, i32 %41)
store i32 1, i32* %4
br label %43
43: ; preds = %36, %33, %25, %14
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @GetAsn1StringBytes(%struct.TYPE_3__* %0, i8* %1, i32 %2) {
%4 = icmp eq %struct.TYPE_3__* %0, null
%5 = icmp slt i32 %2, 0
%6 = or i1 %4, %5
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = xor i32 %9, -1
%11 = lshr i32 %10, 31
%12 = tail call i32 @assert(i32 %11)
%13 = icmp slt i32 %9, 0
br i1 %13, label %24, label %14
14: ; preds = %7
%15 = icmp eq i8* %1, null
%16 = icmp ugt i32 %9, %2
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = sub nsw i32 0, %9
br label %24
20: ; preds = %14
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%22 = load i32, i32* %21
%23 = tail call i32 @memcpy(i8* %1, i32 %22, i32 %9)
br label %24
24: ; preds = %18, %20, %7, %3
%25 = phi i32 [ 0, %3 ], [ %19, %18 ], [ 1, %20 ], [ 0, %7 ]
ret i32 %25
}