#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ base32_decode(int /*<<< orphan*/ *, char const *,
                                 unsigned int);
unsigned int base32_decode_length(unsigned int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ varint_get(int *, int /*<<< orphan*/ *, unsigned int const,
                              unsigned int *);
int client_parse_advert(uint8_t *public, const char *advert, unsigned inlen) {
  uint8_t decoded[384];
  unsigned j = 0;
  char public_found = 0;
  uint32_t v;
  const unsigned len = base32_decode_length(inlen);
  if (len > 384)
    return 0;
  if (!base32_decode(decoded, advert, inlen))
    return 0;
  for (;;) {
    if (j == len)
      break;
    if (!varint_get(&v, decoded, len, &j))
      return 0;
    switch (v >> 1) {
    case 0:
      if (!(v & 1))
        return 0;
      if (!varint_get(&v, decoded, len, &j))
        return 0;
      if (v != 32)
        return 0;
      if (j + v > len)
        return 0;
      memcpy(public, decoded + j, 32);
      public_found = 1;
      j += 32;
      break;
    default:
      if (v & 1) {
        if (!varint_get(&v, decoded, len, &j))
          return 0;
        if (j + v > len)
          return 0;
        j += v;
      }
    }
  }
  return public_found;
}


x86 assembly (clang, -O0):
<client_parse_advert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x624(%rbp)
movb   $0x0,-0x625(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <base32_decode_length@plt>
mov    %eax,-0x630(%rbp)
cmpl   $0x180,-0x630(%rbp)
jbe    1191 <client_parse_advert+0x51>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
lea    -0x620(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <base32_decode@plt>
cmp    $0x0,%eax
jne    11b9 <client_parse_advert+0x79>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
jmp    11be <client_parse_advert+0x7e>
mov    -0x624(%rbp),%eax
cmp    -0x630(%rbp),%eax
jne    11d5 <client_parse_advert+0x95>
jmp    1373 <client_parse_advert+0x233>
lea    -0x620(%rbp),%rsi
mov    -0x630(%rbp),%edx
lea    -0x62c(%rbp),%rdi
lea    -0x624(%rbp),%rcx
call   1050 <varint_get@plt>
cmp    $0x0,%eax
jne    120a <client_parse_advert+0xca>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
mov    -0x62c(%rbp),%eax
sar    %eax
test   %eax,%eax
jne    12ec <client_parse_advert+0x1ac>
jmp    121f <client_parse_advert+0xdf>
mov    -0x62c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    123d <client_parse_advert+0xfd>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
lea    -0x620(%rbp),%rsi
mov    -0x630(%rbp),%edx
lea    -0x62c(%rbp),%rdi
lea    -0x624(%rbp),%rcx
call   1050 <varint_get@plt>
cmp    $0x0,%eax
jne    1272 <client_parse_advert+0x132>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
cmpl   $0x20,-0x62c(%rbp)
je     128b <client_parse_advert+0x14b>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
mov    -0x624(%rbp),%eax
add    -0x62c(%rbp),%eax
cmp    -0x630(%rbp),%eax
jbe    12af <client_parse_advert+0x16f>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
mov    -0x10(%rbp),%rdi
lea    -0x620(%rbp),%rsi
mov    -0x624(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
movb   $0x1,-0x625(%rbp)
mov    -0x624(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x624(%rbp)
jmp    136e <client_parse_advert+0x22e>
mov    -0x62c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1369 <client_parse_advert+0x229>
lea    -0x620(%rbp),%rsi
mov    -0x630(%rbp),%edx
lea    -0x62c(%rbp),%rdi
lea    -0x624(%rbp),%rcx
call   1050 <varint_get@plt>
cmp    $0x0,%eax
jne    1333 <client_parse_advert+0x1f3>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
mov    -0x624(%rbp),%eax
add    -0x62c(%rbp),%eax
cmp    -0x630(%rbp),%eax
jbe    1357 <client_parse_advert+0x217>
movl   $0x0,-0x4(%rbp)
jmp    137d <client_parse_advert+0x23d>
mov    -0x62c(%rbp),%eax
add    -0x624(%rbp),%eax
mov    %eax,-0x624(%rbp)
jmp    136e <client_parse_advert+0x22e>
jmp    11be <client_parse_advert+0x7e>
movsbl -0x625(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_parse_advert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
movl   $0x0,(%rsp)
mov    %edx,%edi
call   1060 <base32_decode_length@plt>
xor    %r14d,%r14d
cmp    $0x180,%eax
ja     1265 <client_parse_advert+0x125>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <base32_decode@plt>
test   %eax,%eax
je     1265 <client_parse_advert+0x125>
test   %ebp,%ebp
je     125f <client_parse_advert+0x11f>
mov    %r12,0x8(%rsp)
xor    %r14d,%r14d
lea    0x4(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %rsp,%r13
xor    %ebx,%ebx
jmp    11bb <client_parse_advert+0x7b>
nop
mov    (%rsp),%eax
cmp    %ebp,%eax
je     1261 <client_parse_advert+0x121>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
call   1050 <varint_get@plt>
test   %eax,%eax
je     1265 <client_parse_advert+0x125>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
ja     1230 <client_parse_advert+0xf0>
test   %eax,%eax
je     1265 <client_parse_advert+0x125>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
call   1050 <varint_get@plt>
test   %eax,%eax
je     1265 <client_parse_advert+0x125>
cmpl   $0x20,0x4(%rsp)
jne    1265 <client_parse_advert+0x125>
mov    (%rsp),%eax
lea    0x20(%rax),%ecx
cmp    %ebp,%ecx
ja     1265 <client_parse_advert+0x125>
lea    (%rsp,%rax,4),%rsi
add    $0x10,%rsi
mov    0x8(%rsp),%rdi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    (%rsp),%eax
add    $0x20,%eax
mov    %eax,(%rsp)
mov    $0x1,%bl
jmp    11b3 <client_parse_advert+0x73>
nopl   (%rax)
test   $0x1,%al
je     11b0 <client_parse_advert+0x70>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
call   1050 <varint_get@plt>
test   %eax,%eax
je     1265 <client_parse_advert+0x125>
mov    0x4(%rsp),%eax
add    (%rsp),%eax
cmp    %ebp,%eax
ja     1265 <client_parse_advert+0x125>
mov    %eax,(%rsp)
jmp    11b3 <client_parse_advert+0x73>
xor    %ebx,%ebx
movzbl %bl,%r14d
mov    %r14d,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @client_parse_advert(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [384 x i32]
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %9
store i8 0, i8* %10
%13 = load i32, i32* %7
%14 = call i32 @base32_decode_length(i32 %13)
store i32 %14, i32* %12
%15 = load i32, i32* %12
%16 = icmp ugt i32 %15, 384
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %97
18: ; preds = %3
%19 = getelementptr inbounds [384 x i32], [384 x i32]* %8, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @base32_decode(i32* %19, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %18
store i32 0, i32* %4
br label %97
25: ; preds = %18
br label %26
26: ; preds = %93, %25
%27 = load i32, i32* %9
%28 = load i32, i32* %12
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
br label %94
31: ; preds = %26
%32 = getelementptr inbounds [384 x i32], [384 x i32]* %8, i64 0, i64 0
%33 = load i32, i32* %12
%34 = call i32 @varint_get(i32* %11, i32* %32, i32 %33, i32* %9)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %31
store i32 0, i32* %4
br label %97
37: ; preds = %31
%38 = load i32, i32* %11
%39 = ashr i32 %38, 1
switch i32 %39, label %71 [
i32 0, label %40
]
40: ; preds = %37
%41 = load i32, i32* %11
%42 = and i32 %41, 1
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
store i32 0, i32* %4
br label %97
45: ; preds = %40
%46 = getelementptr inbounds [384 x i32], [384 x i32]* %8, i64 0, i64 0
%47 = load i32, i32* %12
%48 = call i32 @varint_get(i32* %11, i32* %46, i32 %47, i32* %9)
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %45
store i32 0, i32* %4
br label %97
51: ; preds = %45
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, 32
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 0, i32* %4
br label %97
55: ; preds = %51
%56 = load i32, i32* %9
%57 = load i32, i32* %11
%58 = add i32 %56, %57
%59 = load i32, i32* %12
%60 = icmp ugt i32 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %55
store i32 0, i32* %4
br label %97
62: ; preds = %55
%63 = load i32*, i32** %5
%64 = getelementptr inbounds [384 x i32], [384 x i32]* %8, i64 0, i64 0
%65 = load i32, i32* %9
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = call i32 @memcpy(i32* %63, i32* %67, i32 32)
store i8 1, i8* %10
%69 = load i32, i32* %9
%70 = add i32 %69, 32
store i32 %70, i32* %9
br label %93
71: ; preds = %37
%72 = load i32, i32* %11
%73 = and i32 %72, 1
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %92
75: ; preds = %71
%76 = getelementptr inbounds [384 x i32], [384 x i32]* %8, i64 0, i64 0
%77 = load i32, i32* %12
%78 = call i32 @varint_get(i32* %11, i32* %76, i32 %77, i32* %9)
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %75
store i32 0, i32* %4
br label %97
81: ; preds = %75
%82 = load i32, i32* %9
%83 = load i32, i32* %11
%84 = add i32 %82, %83
%85 = load i32, i32* %12
%86 = icmp ugt i32 %84, %85
br i1 %86, label %87, label %88
87: ; preds = %81
store i32 0, i32* %4
br label %97
88: ; preds = %81
%89 = load i32, i32* %11
%90 = load i32, i32* %9
%91 = add i32 %90, %89
store i32 %91, i32* %9
br label %92
92: ; preds = %88, %71
br label %93
93: ; preds = %92, %62
br label %26
94: ; preds = %30
%95 = load i8, i8* %10
%96 = sext i8 %95 to i32
store i32 %96, i32* %4
br label %97
97: ; preds = %94, %87, %80, %61, %54, %50, %44, %36, %24, %17
%98 = load i32, i32* %4
ret i32 %98
}

LLVM IR (-O2):
define i32 @client_parse_advert(i32* %0, i8* %1, i32 %2) {
%4 = alloca [384 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [384 x i32]* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = bitcast i32* %6 to i8*
%10 = tail call i32 @base32_decode_length(i32 %2)
%11 = icmp ugt i32 %10, 384
br i1 %11, label %64, label %12
12: ; preds = %3
%13 = getelementptr inbounds [384 x i32], [384 x i32]* %4, i64 0, i64 0
%14 = call i32 @base32_decode(i32* %13, i8* %1, i32 %2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %64, label %16
16: ; preds = %12
%17 = icmp eq i32 %10, 0
br i1 %17, label %61, label %18
18: ; preds = %16, %57
%19 = phi i8 [ %59, %57 ], [ 0, %16 ]
%20 = call i32 @varint_get(i32* %6, i32* %13, i32 %10, i32* %5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %64, label %22
22: ; preds = %18
%23 = load i32, i32* %6
%24 = icmp ult i32 %23, 2
br i1 %24, label %25, label %43
25: ; preds = %22
%26 = icmp eq i32 %23, 0
br i1 %26, label %64, label %27
27: ; preds = %25
%28 = call i32 @varint_get(i32* %6, i32* %13, i32 %10, i32* %5)
%29 = icmp ne i32 %28, 0
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 32
%32 = select i1 %29, i1 %31, i1 false
br i1 %32, label %33, label %64
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add i32 %34, 32
%36 = icmp ugt i32 %35, %10
br i1 %36, label %64, label %37
37: ; preds = %33
%38 = zext i32 %34 to i64
%39 = getelementptr inbounds [384 x i32], [384 x i32]* %4, i64 0, i64 %38
%40 = call i32 @memcpy(i32* %0, i32* %39, i32 32)
%41 = load i32, i32* %5
%42 = add i32 %41, 32
store i32 %42, i32* %5
br label %57
43: ; preds = %22
%44 = and i32 %23, 1
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i32, i32* %5
br label %57
48: ; preds = %43
%49 = call i32 @varint_get(i32* %6, i32* %13, i32 %10, i32* %5)
%50 = icmp eq i32 %49, 0
br i1 %50, label %64, label %51
51: ; preds = %48
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = add i32 %53, %52
%55 = icmp ugt i32 %54, %10
br i1 %55, label %64, label %56
56: ; preds = %51
store i32 %54, i32* %5
br label %57
57: ; preds = %46, %56, %37
%58 = phi i32 [ %42, %37 ], [ %54, %56 ], [ %47, %46 ]
%59 = phi i8 [ 1, %37 ], [ %19, %56 ], [ %19, %46 ]
%60 = icmp eq i32 %58, %10
br i1 %60, label %61, label %18
61: ; preds = %57, %16
%62 = phi i8 [ 0, %16 ], [ %59, %57 ]
%63 = zext i8 %62 to i32
br label %64
64: ; preds = %51, %48, %33, %27, %25, %18, %12, %3, %61
%65 = phi i32 [ %63, %61 ], [ 0, %3 ], [ 0, %12 ], [ 0, %18 ], [ 0, %25 ], [ 0, %27 ], [ 0, %33 ], [ 0, %48 ], [ 0, %51 ]
ret i32 %65
}