#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
unsigned char *decode_oid(unsigned char *array, unsigned int *pointer) {
  unsigned char *string = NULL;
  unsigned char *buffer = (unsigned char *)calloc(100, sizeof(unsigned char));
  unsigned char *number = (unsigned char *)calloc(8, sizeof(unsigned char));
  unsigned int oid_node, oid_node_long = 0;
  unsigned char length = array[++*pointer];
  if (array[++*pointer] == 0x2b) {
    strcat((char *)buffer, "1.3");
  }
  length--;
  while (length) {
    ++*pointer;
    oid_node = array[*pointer];
    if (oid_node & 0x80) {
      oid_node_long |= oid_node & 0x7f;
      oid_node_long = oid_node_long << 7;
    } else {
      if (oid_node_long) {
        oid_node_long |= oid_node;
        sprintf((char *)number, ".%d", oid_node_long);
        strcat((char *)buffer, (char *)number);
        oid_node_long = 0;
      } else {
        sprintf((char *)number, ".%d", oid_node);
        strcat((char *)buffer, (char *)number);
      }
    }
    length--;
  }
  string = (unsigned char *)calloc(1, strlen((char *)buffer) + 1);
  strcpy((char *)string, (char *)buffer);
  ++*pointer;
  free(buffer);
  free(number);
  return string;
}


x86 assembly (clang, -O0):
<decode_oid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x64,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
mov    (%rdx),%ecx
add    $0x1,%ecx
mov    %ecx,(%rdx)
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
mov    (%rdx),%ecx
add    $0x1,%ecx
mov    %ecx,(%rdx)
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    11ea <decode_oid+0x8a>
mov    -0x20(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x31(%rbp),%al
add    $0xff,%al
mov    %al,-0x31(%rbp)
cmpb   $0x0,-0x31(%rbp)
je     12b4 <decode_oid+0x154>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1243 <decode_oid+0xe3>
mov    -0x2c(%rbp),%eax
and    $0x7f,%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x30(%rbp)
jmp    12a7 <decode_oid+0x147>
cmpl   $0x0,-0x30(%rbp)
je     1282 <decode_oid+0x122>
mov    -0x2c(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xda0(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
movl   $0x0,-0x30(%rbp)
jmp    12a2 <decode_oid+0x142>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd74(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
jmp    12a7 <decode_oid+0x147>
mov    -0x31(%rbp),%al
add    $0xff,%al
mov    %al,-0x31(%rbp)
jmp    11f2 <decode_oid+0x92>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_oid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r12
mov    $0x64,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    $0x8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    0x0(%rbp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x0(%rbp)
mov    (%r12,%rcx,1),%bl
add    $0x2,%eax
mov    %eax,0x0(%rbp)
cmpb   $0x2b,(%r12,%rax,1)
jne    11be <decode_oid+0x5e>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
add    $0xff,%bl
je     121e <decode_oid+0xbe>
xor    %edx,%edx
lea    0xe38(%rip),%r13
jmp    11df <decode_oid+0x7f>
xchg   %ax,%ax
and    $0x7f,%eax
or     %edx,%eax
shl    $0x7,%eax
mov    %eax,%edx
add    $0xff,%bl
je     121e <decode_oid+0xbe>
mov    0x0(%rbp),%eax
add    $0x1,%eax
mov    %eax,0x0(%rbp)
movzbl (%r12,%rax,1),%eax
test   $0x80,%al
jne    11d0 <decode_oid+0x70>
test   %edx,%edx
jne    11ff <decode_oid+0x9f>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %eax,%edx
jmp    1207 <decode_oid+0xa7>
or     %eax,%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
xor    %edx,%edx
add    $0xff,%bl
jne    11df <decode_oid+0x7f>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
addl   $0x1,0x0(%rbp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"1.3\00"
@.str.1 = [4 x i8] c".%d\00"
define i8* @decode_oid(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %5
%11 = call i64 @calloc(i32 100, i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = call i64 @calloc(i32 8, i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
store i32 0, i32* %9
%15 = load i8*, i8** %3
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = add i32 %17, 1
store i32 %18, i32* %16
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %10
%22 = load i8*, i8** %3
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = add i32 %24, 1
store i32 %25, i32* %23
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = load i8*, i8** %6
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %31, %2
%35 = load i8, i8* %10
%36 = add i8 %35, -1
store i8 %36, i8* %10
br label %37
37: ; preds = %82, %34
%38 = load i8, i8* %10
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %85
40: ; preds = %37
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = add i32 %42, 1
store i32 %43, i32* %41
%44 = load i8*, i8** %3
%45 = load i32*, i32** %4
%46 = load i32, i32* %45
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = and i32 %51, 128
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %40
%55 = load i32, i32* %8
%56 = and i32 %55, 127
%57 = load i32, i32* %9
%58 = or i32 %57, %56
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = shl i32 %59, 7
store i32 %60, i32* %9
br label %82
61: ; preds = %40
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %61
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = or i32 %66, %65
store i32 %67, i32* %9
%68 = load i8*, i8** %7
%69 = load i32, i32* %9
%70 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i8*, i8** %6
%72 = load i8*, i8** %7
%73 = call i32 @strcat(i8* %71, i8* %72)
store i32 0, i32* %9
br label %81
74: ; preds = %61
%75 = load i8*, i8** %7
%76 = load i32, i32* %8
%77 = call i32 @sprintf(i8* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %76)
%78 = load i8*, i8** %6
%79 = load i8*, i8** %7
%80 = call i32 @strcat(i8* %78, i8* %79)
br label %81
81: ; preds = %74, %64
br label %82
82: ; preds = %81, %54
%83 = load i8, i8* %10
%84 = add i8 %83, -1
store i8 %84, i8* %10
br label %37
85: ; preds = %37
%86 = load i8*, i8** %6
%87 = call i32 @strlen(i8* %86)
%88 = add nsw i32 %87, 1
%89 = call i64 @calloc(i32 1, i32 %88)
%90 = inttoptr i64 %89 to i8*
store i8* %90, i8** %5
%91 = load i8*, i8** %5
%92 = load i8*, i8** %6
%93 = call i32 @strcpy(i8* %91, i8* %92)
%94 = load i32*, i32** %4
%95 = load i32, i32* %94
%96 = add i32 %95, 1
store i32 %96, i32* %94
%97 = load i8*, i8** %6
%98 = call i32 @free(i8* %97)
%99 = load i8*, i8** %7
%100 = call i32 @free(i8* %99)
%101 = load i8*, i8** %5
ret i8* %101
}

LLVM IR (-O2):
@.str = [4 x i8] c"1.3\00"
@.str.1 = [4 x i8] c".%d\00"
define i8* @decode_oid(i8* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @calloc(i32 100, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @calloc(i32 8, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = load i32, i32* %1
%8 = add i32 %7, 1
store i32 %8, i32* %1
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = add i32 %7, 2
store i32 %12, i32* %1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 43
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = add i8 %11, -1
%21 = icmp eq i8 %20, 0
br i1 %21, label %50, label %22
22: ; preds = %19, %46
%23 = phi i8 [ %48, %46 ], [ %20, %19 ]
%24 = phi i32 [ %47, %46 ], [ 0, %19 ]
%25 = load i32, i32* %1
%26 = add i32 %25, 1
store i32 %26, i32* %1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 128
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %22
%34 = and i32 %30, 127
%35 = or i32 %34, %24
%36 = shl i32 %35, 7
br label %46
37: ; preds = %22
%38 = icmp eq i32 %24, 0
br i1 %38, label %43, label %39
39: ; preds = %37
%40 = or i32 %24, %30
%41 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = tail call i32 @strcat(i8* %4, i8* %6)
br label %46
43: ; preds = %37
%44 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%45 = tail call i32 @strcat(i8* %4, i8* %6)
br label %46
46: ; preds = %39, %43, %33
%47 = phi i32 [ %36, %33 ], [ 0, %39 ], [ 0, %43 ]
%48 = add i8 %23, -1
%49 = icmp eq i8 %48, 0
br i1 %49, label %50, label %22
50: ; preds = %46, %19
%51 = tail call i32 @strlen(i8* %4)
%52 = add nsw i32 %51, 1
%53 = tail call i64 @calloc(i32 1, i32 %52)
%54 = inttoptr i64 %53 to i8*
%55 = tail call i32 @strcpy(i8* %54, i8* %4)
%56 = load i32, i32* %1
%57 = add i32 %56, 1
store i32 %57, i32* %1
%58 = tail call i32 @free(i8* %4)
%59 = tail call i32 @free(i8* %6)
ret i8* %54
}