#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 /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ parsepayload(char *, int *, char *);
int querycns(int, int, int, int, char *);
int strlen(char *);
int strtol(char *, char **, int);
int queryoid(char *oidspec) {
  int oid;
  int op;
  char *end;
  oid = strtol(oidspec, &end, 16);
  if (end != oidspec + 4)
    errx(5, "4-digit hex number expected, got %s", oidspec);
  switch (oidspec[4]) {
  case ':':
    op = 0x01;
    break;
  case '=':
    op = 0x03;
    break;
  case '+':
    op = 0x05;
    break;
  case '-':
    op = 0x08;
    break;
  case '\0':
    op = 0x01;
    break;
  default:
    errx(5, "bad op specification: %s", oidspec);
  }
  int speclen = oidspec[4] ? strlen(oidspec + 5) : 0;
  int len = speclen / 2;
  char payload[len];
  if (speclen)
    parsepayload(oidspec + 5, &len, payload);
  return querycns(((1 << 0) | (1 << 1)), oid, op, len, payload);
}


x86 assembly (clang, -O0):
<queryoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
je     119b <queryoid+0x4b>
mov    -0x8(%rbp),%rdx
mov    $0x5,%edi
lea    0xe6a(%rip),%rsi
call   1040 <errx@plt>
mov    -0x8(%rbp),%rax
movsbl 0x4(%rax),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1227 <queryoid+0xd7>
jmp    11b3 <queryoid+0x63>
mov    -0x34(%rbp),%eax
sub    $0x2b,%eax
je     120f <queryoid+0xbf>
jmp    11c4 <queryoid+0x74>
mov    -0x34(%rbp),%eax
sub    $0x2d,%eax
je     121b <queryoid+0xcb>
jmp    11d5 <queryoid+0x85>
mov    -0x34(%rbp),%eax
sub    $0x3a,%eax
je     11f7 <queryoid+0xa7>
jmp    11e6 <queryoid+0x96>
mov    -0x34(%rbp),%eax
sub    $0x3d,%eax
je     1203 <queryoid+0xb3>
jmp    1233 <queryoid+0xe3>
movl   $0x1,-0x10(%rbp)
jmp    1248 <queryoid+0xf8>
movl   $0x3,-0x10(%rbp)
jmp    1248 <queryoid+0xf8>
movl   $0x5,-0x10(%rbp)
jmp    1248 <queryoid+0xf8>
movl   $0x8,-0x10(%rbp)
jmp    1248 <queryoid+0xf8>
movl   $0x1,-0x10(%rbp)
jmp    1248 <queryoid+0xf8>
mov    -0x8(%rbp),%rdx
mov    $0x5,%edi
lea    0xde1(%rip),%rsi
call   1040 <errx@plt>
mov    -0x8(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
je     126e <queryoid+0x11e>
mov    -0x8(%rbp),%rdi
add    $0x5,%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
jmp    1278 <queryoid+0x128>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    1278 <queryoid+0x128>
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
sar    %eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12d2 <queryoid+0x182>
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rdi
add    $0x5,%rdi
lea    -0x20(%rbp),%rsi
call   1050 <parsepayload@plt>
mov    -0x40(%rbp),%r8
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0x3,%edi
call   1070 <querycns@plt>
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queryoid>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
lea    0x4(%r12),%rbx
cmp    %rbx,-0x40(%rbp)
je     1194 <queryoid+0x44>
lea    0xec5(%rip),%rsi
mov    $0x5,%edi
mov    %r12,%rdx
call   1040 <errx@plt>
mov    (%rbx),%al
movsbl %al,%ecx
mov    $0x1,%r15d
lea    -0x2b(%rcx),%edx
cmp    $0x12,%edx
ja     11c3 <queryoid+0x73>
lea    0xe52(%rip),%rcx
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    $0x5,%r15d
test   %al,%al
jne    11f0 <queryoid+0xa0>
jmp    1242 <queryoid+0xf2>
test   %ecx,%ecx
je     11ec <queryoid+0x9c>
lea    0xea2(%rip),%rsi
mov    $0x5,%edi
mov    %r12,%rdx
call   1040 <errx@plt>
mov    0x4(%r12),%al
test   %al,%al
jne    11f0 <queryoid+0xa0>
jmp    1242 <queryoid+0xf2>
mov    $0x8,%r15d
test   %al,%al
je     1242 <queryoid+0xf2>
add    $0x5,%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r13
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,-0x34(%rbp)
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %eax,%eax
je     1234 <queryoid+0xe4>
lea    -0x34(%rbp),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
call   1050 <parsepayload@plt>
mov    -0x34(%rbp),%ecx
jmp    1252 <queryoid+0x102>
xor    %ecx,%ecx
jmp    1252 <queryoid+0x102>
mov    $0x3,%r15d
test   %al,%al
jne    11f0 <queryoid+0xa0>
mov    %rsp,%r13
movl   $0x0,-0x34(%rbp)
xor    %ecx,%ecx
lea    -0x30(%rbp),%rbx
mov    $0x3,%edi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %rbx,%r8
call   1070 <querycns@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"4-digit hex number expected, got %s\00"
@.str.1 = [25 x i8] c"bad op specification: %s\00"
define i32 @queryoid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strtol(i8* %10, i8** %5, i32 16)
store i32 %11, i32* %3
%12 = load i8*, i8** %5
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = icmp ne i8* %12, %14
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i32 @errx(i32 5, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %1
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %29 [
i32 58, label %24
i32 61, label %25
i32 43, label %26
i32 45, label %27
i32 0, label %28
]
24: ; preds = %19
store i32 1, i32* %4
br label %32
25: ; preds = %19
store i32 3, i32* %4
br label %32
26: ; preds = %19
store i32 5, i32* %4
br label %32
27: ; preds = %19
store i32 8, i32* %4
br label %32
28: ; preds = %19
store i32 1, i32* %4
br label %32
29: ; preds = %19
%30 = load i8*, i8** %2
%31 = call i32 @errx(i32 5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %28, %27, %26, %25, %24
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 5
%41 = call i32 @strlen(i8* %40)
br label %43
42: ; preds = %32
br label %43
43: ; preds = %42, %38
%44 = phi i32 [ %41, %38 ], [ 0, %42 ]
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = sdiv i32 %45, 2
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = zext i32 %47 to i64
%49 = call i8* @llvm.stacksave()
store i8* %49, i8** %8
%50 = alloca i8, i64 %48
store i64 %48, i64* %9
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %43
%54 = load i8*, i8** %2
%55 = getelementptr inbounds i8, i8* %54, i64 5
%56 = call i32 @parsepayload(i8* %55, i32* %7, i8* %50)
br label %57
57: ; preds = %53, %43
%58 = load i32, i32* %3
%59 = load i32, i32* %4
%60 = load i32, i32* %7
%61 = call i32 @querycns(i32 3, i32 %58, i32 %59, i32 %60, i8* %50)
%62 = load i8*, i8** %8
ret i32 %61
}

LLVM IR (-O2):
@.str = [36 x i8] c"4-digit hex number expected, got %s\00"
@.str.1 = [25 x i8] c"bad op specification: %s\00"
define i32 @queryoid(i8* %0) {
%2 = alloca [0 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
%6 = call i32 @strtol(i8* %0, i8** %3, i32 16)
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = icmp eq i8* %7, %8
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @errx(i32 5, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %1
%13 = load i8, i8* %8
%14 = sext i8 %13 to i32
switch i32 %14, label %18 [
i32 58, label %21
i32 61, label %15
i32 43, label %16
i32 45, label %17
i32 0, label %21
]
15: ; preds = %12
br label %21
16: ; preds = %12
br label %21
17: ; preds = %12
br label %21
18: ; preds = %12
%19 = tail call i32 @errx(i32 5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = load i8, i8* %8
br label %21
21: ; preds = %12, %12, %18, %17, %16, %15
%22 = phi i8 [ %13, %12 ], [ %13, %12 ], [ %20, %18 ], [ %13, %17 ], [ %13, %16 ], [ %13, %15 ]
%23 = phi i32 [ 1, %12 ], [ 1, %12 ], [ undef, %18 ], [ 8, %17 ], [ 5, %16 ], [ 3, %15 ]
%24 = icmp eq i8 %22, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%27 = tail call i8* @llvm.stacksave()
%28 = getelementptr inbounds [0 x i8], [0 x i8]* %2, i64 0, i64 0
br label %41
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %0, i64 5
%31 = tail call i32 @strlen(i8* %30)
%32 = bitcast i32* %4 to i8*
%33 = sdiv i32 %31, 2
store i32 %33, i32* %4
%34 = zext i32 %33 to i64
%35 = tail call i8* @llvm.stacksave()
%36 = alloca i8, i64 %34
%37 = icmp eq i32 %31, 0
br i1 %37, label %41, label %38
38: ; preds = %29
%39 = call i32 @parsepayload(i8* %30, i32* %4, i8* %36)
%40 = load i32, i32* %4
br label %41
41: ; preds = %25, %38, %29
%42 = phi i32 [ 0, %25 ], [ %40, %38 ], [ 0, %29 ]
%43 = phi i8* [ %28, %25 ], [ %36, %38 ], [ %36, %29 ]
%44 = phi i8* [ %27, %25 ], [ %35, %38 ], [ %35, %29 ]
%45 = bitcast i32* %4 to i8*
%46 = call i32 @querycns(i32 3, i32 %6, i32 %23, i32 %42, i8* %43)
ret i32 %46
}