#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(6, sizeof(unsigned char));
  unsigned int oid_node, oid_node_long = 0;
  *pointer = *pointer + 1;
  unsigned char length = array[*pointer];
  *pointer = *pointer + 1;
  if (array[*pointer] == 0x2b) {
    strcat((char *)buffer, "1.3");
  }
  length--;
  while (length) {
    *pointer = *pointer + 1;
    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 = *pointer + 1;
  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    $0x6,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    11fa <decode_oid+0x9a>
mov    -0x20(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x31(%rbp),%al
add    $0xff,%al
mov    %al,-0x31(%rbp)
cmpb   $0x0,-0x31(%rbp)
je     12c8 <decode_oid+0x168>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
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     1257 <decode_oid+0xf7>
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    12bb <decode_oid+0x15b>
cmpl   $0x0,-0x30(%rbp)
je     1296 <decode_oid+0x136>
mov    -0x2c(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xd8c(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
movl   $0x0,-0x30(%rbp)
jmp    12b6 <decode_oid+0x156>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd60(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
jmp    12bb <decode_oid+0x15b>
mov    -0x31(%rbp),%al
add    $0xff,%al
mov    %al,-0x31(%rbp)
jmp    1202 <decode_oid+0xa2>
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    -0x10(%rbp),%rax
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    $0x6,%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 6, i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
store i32 0, i32* %9
%15 = load i32*, i32** %4
%16 = load i32, i32* %15
%17 = add i32 %16, 1
%18 = load i32*, i32** %4
store i32 %17, i32* %18
%19 = load i8*, i8** %3
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %10
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = add i32 %26, 1
%28 = load i32*, i32** %4
store i32 %27, i32* %28
%29 = load i8*, i8** %3
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 43
br i1 %36, label %37, label %40
37: ; preds = %2
%38 = load i8*, i8** %6
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %37, %2
%41 = load i8, i8* %10
%42 = add i8 %41, -1
store i8 %42, i8* %10
br label %43
43: ; preds = %89, %40
%44 = load i8, i8* %10
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %92
46: ; preds = %43
%47 = load i32*, i32** %4
%48 = load i32, i32* %47
%49 = add i32 %48, 1
%50 = load i32*, i32** %4
store i32 %49, i32* %50
%51 = load i8*, i8** %3
%52 = load i32*, i32** %4
%53 = load i32, i32* %52
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = and i32 %58, 128
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %46
%62 = load i32, i32* %8
%63 = and i32 %62, 127
%64 = load i32, i32* %9
%65 = or i32 %64, %63
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = shl i32 %66, 7
store i32 %67, i32* %9
br label %89
68: ; preds = %46
%69 = load i32, i32* %9
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %68
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = or i32 %73, %72
store i32 %74, i32* %9
%75 = load i8*, i8** %7
%76 = load i32, i32* %9
%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)
store i32 0, i32* %9
br label %88
81: ; preds = %68
%82 = load i8*, i8** %7
%83 = load i32, i32* %8
%84 = call i32 @sprintf(i8* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %83)
%85 = load i8*, i8** %6
%86 = load i8*, i8** %7
%87 = call i32 @strcat(i8* %85, i8* %86)
br label %88
88: ; preds = %81, %71
br label %89
89: ; preds = %88, %61
%90 = load i8, i8* %10
%91 = add i8 %90, -1
store i8 %91, i8* %10
br label %43
92: ; preds = %43
%93 = load i8*, i8** %6
%94 = call i32 @strlen(i8* %93)
%95 = add nsw i32 %94, 1
%96 = call i64 @calloc(i32 1, i32 %95)
%97 = inttoptr i64 %96 to i8*
store i8* %97, i8** %5
%98 = load i8*, i8** %5
%99 = load i8*, i8** %6
%100 = call i32 @strcpy(i8* %98, i8* %99)
%101 = load i32*, i32** %4
%102 = load i32, i32* %101
%103 = add i32 %102, 1
%104 = load i32*, i32** %4
store i32 %103, i32* %104
%105 = load i8*, i8** %6
%106 = call i32 @free(i8* %105)
%107 = load i8*, i8** %7
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %5
ret i8* %109
}

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 6, 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
}