#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 NetFrame {
  int dummy;
};

/* Variables and functions */
unsigned int asn1_length(struct NetFrame *, unsigned char const *, unsigned int,
                         unsigned int *);
unsigned int asn1_tag(unsigned char const *, unsigned int, unsigned int *);
void asn1_string(struct NetFrame *frame, const unsigned char *px,
                 unsigned length, unsigned *r_offset,
                 const unsigned char **r_str, unsigned *r_str_length) {
  unsigned len;
  unsigned tag;
  if (*r_offset >= length)
    return;
  tag = asn1_tag(px, length, r_offset);
  len = asn1_length(frame, px, length, r_offset);
  *r_str = px + *r_offset;
  *r_str_length = len;
  *r_offset += len;
}


x86 assembly (clang, -O0):
<asn1_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jb     1153 <asn1_string+0x33>
jmp    11a5 <asn1_string+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <asn1_tag@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <asn1_length@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,(%rcx)
jae    116a <asn1_string+0x4a>
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rcx,%rdx
call   1040 <asn1_tag@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <asn1_length@plt>
mov    (%rbx),%ecx
add    %r12,%rcx
mov    %rcx,(%r15)
mov    %eax,(%r14)
add    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.NetFrame = type { i32 }
define void @asn1_string(%struct.NetFrame* %0, i8* %1, i32 %2, i32* %3, i8** %4, i32* %5) {
%7 = alloca %struct.NetFrame*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store %struct.NetFrame* %0, %struct.NetFrame** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i8** %4, i8*** %11
store i32* %5, i32** %12
%15 = load i32*, i32** %10
%16 = load i32, i32* %15
%17 = load i32, i32* %9
%18 = icmp uge i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %6
br label %42
20: ; preds = %6
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = load i32*, i32** %10
%24 = call i32 @asn1_tag(i8* %21, i32 %22, i32* %23)
store i32 %24, i32* %14
%25 = load %struct.NetFrame*, %struct.NetFrame** %7
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = load i32*, i32** %10
%29 = call i32 @asn1_length(%struct.NetFrame* %25, i8* %26, i32 %27, i32* %28)
store i32 %29, i32* %13
%30 = load i8*, i8** %8
%31 = load i32*, i32** %10
%32 = load i32, i32* %31
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8**, i8*** %11
store i8* %34, i8** %35
%36 = load i32, i32* %13
%37 = load i32*, i32** %12
store i32 %36, i32* %37
%38 = load i32, i32* %13
%39 = load i32*, i32** %10
%40 = load i32, i32* %39
%41 = add i32 %40, %38
store i32 %41, i32* %39
br label %42
42: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
%struct.NetFrame = type { i32 }
define void @asn1_string(%struct.NetFrame* %0, i8* %1, i32 %2, i32* %3, i8** nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = load i32, i32* %3
%8 = icmp ult i32 %7, %2
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = tail call i32 @asn1_tag(i8* %1, i32 %2, i32* %3)
%11 = tail call i32 @asn1_length(%struct.NetFrame* %0, i8* %1, i32 %2, i32* %3)
%12 = load i32, i32* %3
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8* %14, i8** %4
store i32 %11, i32* %5
%15 = load i32, i32* %3
%16 = add i32 %15, %11
store i32 %16, i32* %3
br label %17
17: ; preds = %6, %9
ret void
}