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

/* Variables and functions */
int /*<<< orphan*/ asn1_octet_decode(struct asn1_ctx *, unsigned char *);
unsigned char asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid) {
  unsigned char ch;
  *subid = 0;
  do {
    if (!asn1_octet_decode(ctx, &ch))
      return 0;
    *subid <<= 7;
    *subid |= ch & 0x7F;
  } while ((ch & 0x80) == 0x80);
  return 1;
}


x86 assembly (clang, -O0):
<asn1_subid_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x19(%rbp),%rsi
call   1030 <asn1_octet_decode@plt>
cmp    $0x0,%eax
jne    114a <asn1_subid_decode+0x3a>
movb   $0x0,-0x1(%rbp)
jmp    1184 <asn1_subid_decode+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0x7,%rcx
mov    %rcx,(%rax)
movzbl -0x19(%rbp),%eax
and    $0x7f,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
movzbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x80,%eax
je     112b <asn1_subid_decode+0x1b>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_subid_decode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,(%rsi)
lea    0xf(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <asn1_octet_decode@plt>
test   %eax,%eax
je     115e <asn1_subid_decode+0x4e>
mov    (%rbx),%rax
shl    $0x7,%rax
movzbl 0xf(%rsp),%ecx
mov    %ecx,%edx
and    $0x7f,%edx
or     %rax,%rdx
mov    %rdx,(%rbx)
test   %cl,%cl
js     1130 <asn1_subid_decode+0x20>
mov    $0x1,%al
jmp    1160 <asn1_subid_decode+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.asn1_ctx = type { i32 }
define zeroext i8 @asn1_subid_decode(%struct.asn1_ctx* %0, i64* %1) {
%3 = alloca i8
%4 = alloca %struct.asn1_ctx*
%5 = alloca i64*
%6 = alloca i8
store %struct.asn1_ctx* %0, %struct.asn1_ctx** %4
store i64* %1, i64** %5
%7 = load i64*, i64** %5
store i64 0, i64* %7
br label %8
8: ; preds = %24, %2
%9 = load %struct.asn1_ctx*, %struct.asn1_ctx** %4
%10 = call i32 @asn1_octet_decode(%struct.asn1_ctx* %9, i8* %6)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8
store i8 0, i8* %3
br label %30
13: ; preds = %8
%14 = load i64*, i64** %5
%15 = load i64, i64* %14
%16 = shl i64 %15, 7
store i64 %16, i64* %14
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = and i32 %18, 127
%20 = sext i32 %19 to i64
%21 = load i64*, i64** %5
%22 = load i64, i64* %21
%23 = or i64 %22, %20
store i64 %23, i64* %21
br label %24
24: ; preds = %13
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = and i32 %26, 128
%28 = icmp eq i32 %27, 128
br i1 %28, label %8, label %29
29: ; preds = %24
store i8 1, i8* %3
br label %30
30: ; preds = %29, %12
%31 = load i8, i8* %3
ret i8 %31
}

LLVM IR (-O2):
%struct.asn1_ctx = type { i32 }
define zeroext i8 @asn1_subid_decode(%struct.asn1_ctx* %0, i64* nocapture %1) {
%3 = alloca i8
store i64 0, i64* %1
br label %4
4: ; preds = %7, %2
%5 = call i32 @asn1_octet_decode(%struct.asn1_ctx* %0, i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = load i64, i64* %1
%9 = shl i64 %8, 7
%10 = load i8, i8* %3
%11 = and i8 %10, 127
%12 = zext i8 %11 to i64
%13 = or i64 %9, %12
store i64 %13, i64* %1
%14 = icmp slt i8 %10, 0
br i1 %14, label %4, label %15
15: ; preds = %7, %4
%16 = phi i8 [ 0, %4 ], [ 1, %7 ]
ret i8 %16
}