#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_tag_decode(struct asn1_ctx *ctx, unsigned int *tag) {
  unsigned char ch;
  *tag = 0;
  do {
    if (!asn1_octet_decode(ctx, &ch))
      return 0;
    *tag <<= 7;
    *tag |= ch & 0x7F;
  } while ((ch & 0x80) == 0x80);
  return 1;
}


x86 assembly (clang, -O0):
<asn1_tag_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x19(%rbp),%rsi
call   1030 <asn1_octet_decode@plt>
cmp    $0x0,%eax
jne    1149 <asn1_tag_decode+0x39>
movb   $0x0,-0x1(%rbp)
jmp    117b <asn1_tag_decode+0x6b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x7,%ecx
mov    %ecx,(%rax)
movzbl -0x19(%rbp),%ecx
and    $0x7f,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
movzbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x80,%eax
je     112a <asn1_tag_decode+0x1a>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_tag_decode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,(%rsi)
lea    0xf(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <asn1_octet_decode@plt>
test   %eax,%eax
je     115a <asn1_tag_decode+0x4a>
mov    (%rbx),%eax
shl    $0x7,%eax
movzbl 0xf(%rsp),%ecx
mov    %ecx,%edx
and    $0x7f,%edx
or     %eax,%edx
mov    %edx,(%rbx)
test   %cl,%cl
js     1130 <asn1_tag_decode+0x20>
mov    $0x1,%al
jmp    115c <asn1_tag_decode+0x4c>
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_tag_decode(%struct.asn1_ctx* %0, i32* %1) {
%3 = alloca i8
%4 = alloca %struct.asn1_ctx*
%5 = alloca i32*
%6 = alloca i8
store %struct.asn1_ctx* %0, %struct.asn1_ctx** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
store i32 0, i32* %7
br label %8
8: ; preds = %23, %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 %29
13: ; preds = %8
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = shl i32 %15, 7
store i32 %16, i32* %14
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = and i32 %18, 127
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
br label %23
23: ; preds = %13
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = and i32 %25, 128
%27 = icmp eq i32 %26, 128
br i1 %27, label %8, label %28
28: ; preds = %23
store i8 1, i8* %3
br label %29
29: ; preds = %28, %12
%30 = load i8, i8* %3
ret i8 %30
}

LLVM IR (-O2):
%struct.asn1_ctx = type { i32 }
define zeroext i8 @asn1_tag_decode(%struct.asn1_ctx* %0, i32* nocapture %1) {
%3 = alloca i8
store i32 0, i32* %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 i32, i32* %1
%9 = shl i32 %8, 7
%10 = load i8, i8* %3
%11 = and i8 %10, 127
%12 = zext i8 %11 to i32
%13 = or i32 %9, %12
store i32 %13, i32* %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
}