#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 INT_MAX;
int ASN1_object_size(int constructed, int length, int tag) {
  int ret = 1;
  if (length < 0)
    return -1;
  if (tag >= 31) {
    while (tag > 0) {
      tag >>= 7;
      ret++;
    }
  }
  if (constructed == 2) {
    ret += 3;
  } else {
    ret++;
    if (length > 127) {
      int tmplen = length;
      while (tmplen > 0) {
        tmplen >>= 8;
        ret++;
      }
    }
  }
  if (ret >= INT_MAX - length)
    return -1;
  return ret + length;
}


x86 assembly (clang, -O0):
<ASN1_object_size>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    112a <ASN1_object_size+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <ASN1_object_size+0xe7>
cmpl   $0x1f,-0x10(%rbp)
jl     115f <ASN1_object_size+0x5f>
jmp    1139 <ASN1_object_size+0x39>
cmpl   $0x0,-0x10(%rbp)
jle    115a <ASN1_object_size+0x5a>
mov    -0x10(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <ASN1_object_size+0x39>
jmp    115f <ASN1_object_size+0x5f>
cmpl   $0x2,-0x8(%rbp)
jne    1177 <ASN1_object_size+0x77>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <ASN1_object_size+0xbb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x7f,-0xc(%rbp)
jle    11b6 <ASN1_object_size+0xb6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11b1 <ASN1_object_size+0xb1>
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <ASN1_object_size+0x90>
jmp    11b6 <ASN1_object_size+0xb6>
jmp    11bb <ASN1_object_size+0xbb>
mov    -0x14(%rbp),%eax
mov    0x2e23(%rip),%rcx
mov    (%rcx),%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jl     11de <ASN1_object_size+0xde>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <ASN1_object_size+0xe7>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_object_size>:
test   %esi,%esi
js     1137 <ASN1_object_size+0x37>
mov    $0x1,%eax
cmp    $0x1f,%edx
jl     112d <ASN1_object_size+0x2d>
mov    $0x1,%eax
mov    %edx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
sar    $0x7,%ecx
add    $0x1,%eax
cmp    $0x7f,%edx
mov    %ecx,%edx
jg     1120 <ASN1_object_size+0x20>
cmp    $0x2,%edi
jne    113d <ASN1_object_size+0x3d>
add    $0x3,%eax
jmp    1160 <ASN1_object_size+0x60>
mov    $0xffffffff,%eax
ret
add    $0x1,%eax
cmp    $0x80,%esi
jl     1160 <ASN1_object_size+0x60>
mov    %esi,%ecx
mov    %esi,%edx
nopl   0x0(%rax)
shr    $0x8,%edx
add    $0x1,%eax
cmp    $0xff,%ecx
mov    %edx,%ecx
ja     1150 <ASN1_object_size+0x50>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%ecx
sub    %esi,%ecx
add    %eax,%esi
cmp    %ecx,%eax
mov    $0xffffffff,%eax
cmovl  %esi,%eax
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @ASN1_object_size(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 1, i32* %8
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %60
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 31
br i1 %15, label %16, label %26
16: ; preds = %13
br label %17
17: ; preds = %20, %16
%18 = load i32, i32* %7
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %7
%22 = ashr i32 %21, 7
store i32 %22, i32* %7
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
br label %17
25: ; preds = %17
br label %26
26: ; preds = %25, %13
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 3
store i32 %31, i32* %8
br label %49
32: ; preds = %26
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
%35 = load i32, i32* %6
%36 = icmp sgt i32 %35, 127
br i1 %36, label %37, label %48
37: ; preds = %32
%38 = load i32, i32* %6
store i32 %38, i32* %9
br label %39
39: ; preds = %42, %37
%40 = load i32, i32* %9
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* %9
%44 = ashr i32 %43, 8
store i32 %44, i32* %9
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %39
47: ; preds = %39
br label %48
48: ; preds = %47, %32
br label %49
49: ; preds = %48, %29
%50 = load i32, i32* %8
%51 = load i32, i32* @INT_MAX
%52 = load i32, i32* %6
%53 = sub nsw i32 %51, %52
%54 = icmp sge i32 %50, %53
br i1 %54, label %55, label %56
55: ; preds = %49
store i32 -1, i32* %4
br label %60
56: ; preds = %49
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = add nsw i32 %57, %58
store i32 %59, i32* %4
br label %60
60: ; preds = %56, %55, %12
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @ASN1_object_size(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 0
br i1 %4, label %34, label %5
5: ; preds = %3
%6 = icmp sgt i32 %2, 30
br i1 %6, label %7, label %13
7: ; preds = %5, %7
%8 = phi i32 [ %10, %7 ], [ %2, %5 ]
%9 = phi i32 [ %11, %7 ], [ 1, %5 ]
%10 = ashr i32 %8, 7
%11 = add nuw nsw i32 %9, 1
%12 = icmp sgt i32 %8, 127
br i1 %12, label %7, label %13
13: ; preds = %7, %5
%14 = phi i32 [ 1, %5 ], [ %11, %7 ]
%15 = icmp eq i32 %0, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = add nsw i32 %14, 3
br label %27
18: ; preds = %13
%19 = add nsw i32 %14, 1
%20 = icmp sgt i32 %1, 127
br i1 %20, label %21, label %27
21: ; preds = %18, %21
%22 = phi i32 [ %24, %21 ], [ %1, %18 ]
%23 = phi i32 [ %25, %21 ], [ %19, %18 ]
%24 = lshr i32 %22, 8
%25 = add nsw i32 %23, 1
%26 = icmp ult i32 %22, 256
br i1 %26, label %27, label %21
27: ; preds = %21, %18, %16
%28 = phi i32 [ %17, %16 ], [ %19, %18 ], [ %25, %21 ]
%29 = load i32, i32* @INT_MAX
%30 = sub nsw i32 %29, %1
%31 = icmp slt i32 %28, %30
%32 = add nsw i32 %28, %1
%33 = select i1 %31, i32 %32, i32 -1
br label %34
34: ; preds = %27, %3
%35 = phi i32 [ -1, %3 ], [ %33, %27 ]
ret i32 %35
}