#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*/ decode_get_config_feature(int, unsigned char *, int);
int /*<<< orphan*/ printf(char *, int);
void decode_get_config(unsigned char *resp, int max_resp_len, int len) {
  int k, extra, feature;
  unsigned char *ucp;
  if (max_resp_len < len) {
    printf("get_config: response to long for buffer, resp_len=%d>>>\n", len);
    len = max_resp_len;
  }
  if (len < 8) {
    printf("get_config: response length too short: %d\n", len);
    return;
  }
  ucp = resp + 8;
  len -= 8;
  for (k = 0; k < len; k += extra, ucp += extra) {
    extra = 4 + ucp[3];
    feature = (ucp[0] << 8) + ucp[1];
    if (0 != (extra % 4))
      printf("    get_config: additional length [%d] not a multiple "
             "of 4, ignore\n",
             extra - 4);
    else
      decode_get_config_feature(feature, ucp, extra);
  }
}


x86 assembly (clang, -O0):
<decode_get_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1153 <decode_get_config+0x33>
mov    -0x10(%rbp),%esi
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1171 <decode_get_config+0x51>
mov    -0x10(%rbp),%esi
lea    0xed2(%rip),%rdi
call   1040 <printf@plt>
jmp    121d <decode_get_config+0xfd>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    121d <decode_get_config+0xfd>
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x28(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
je     11ea <decode_get_config+0xca>
mov    -0x18(%rbp),%esi
sub    $0x4,%esi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
jmp    11f9 <decode_get_config+0xd9>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <decode_get_config_feature@plt>
jmp    11fe <decode_get_config+0xde>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    118d <decode_get_config+0x6d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_get_config>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
cmp    %edx,%esi
jge    1155 <decode_get_config+0x35>
mov    %esi,%r15d
lea    0xec7(%rip),%rdi
mov    %edx,%esi
call   1040 <printf@plt>
cmp    $0x7,%r15d
jle    115e <decode_get_config+0x3e>
cmp    $0x8,%r15d
jne    1175 <decode_get_config+0x55>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%r15d
cmp    $0x7,%r15d
jg     1146 <decode_get_config+0x26>
lea    0xed4(%rip),%rdi
mov    %r15d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0xfffffff8,%r15d
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0xede(%rip),%r14
jmp    11ae <decode_get_config+0x8e>
nopl   0x0(%rax,%rax,1)
movzwl (%rbx),%edi
shl    $0x10,%edi
bswap  %edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <decode_get_config_feature@plt>
add    %r12d,%ebp
add    %r12,%rbx
cmp    %r15d,%ebp
jge    114c <decode_get_config+0x2c>
movzbl 0x3(%rbx),%esi
lea    0x4(%rsi),%r12
test   $0x3,%sil
je     1190 <decode_get_config+0x70>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    11a3 <decode_get_config+0x83>

LLVM IR (-O0):
@.str = [57 x i8] c"get_config: response to long for buffer, resp_len=%d>>>\0A\00"
@.str.1 = [43 x i8] c"get_config: response length too short: %d\0A\00"
@.str.2 = [68 x i8] c" get_config: additional length [%d] not a multiple of 4, ignore\0A\00"
define void @decode_get_config(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
store i32 %17, i32* %6
br label %18
18: ; preds = %14, %3
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %70
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 8
store i8* %26, i8** %10
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 8
store i32 %28, i32* %6
store i32 0, i32* %7
br label %29
29: ; preds = %62, %24
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %70
33: ; preds = %29
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = add nsw i32 4, %37
store i32 %38, i32* %8
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = shl i32 %42, 8
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = add nsw i32 %43, %47
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = srem i32 %49, 4
%51 = icmp ne i32 0, %50
br i1 %51, label %52, label %56
52: ; preds = %33
%53 = load i32, i32* %8
%54 = sub nsw i32 %53, 4
%55 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %61
56: ; preds = %33
%57 = load i32, i32* %9
%58 = load i8*, i8** %10
%59 = load i32, i32* %8
%60 = call i32 @decode_get_config_feature(i32 %57, i8* %58, i32 %59)
br label %61
61: ; preds = %56, %52
br label %62
62: ; preds = %61
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = add nsw i32 %64, %63
store i32 %65, i32* %7
%66 = load i32, i32* %8
%67 = load i8*, i8** %10
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8* %69, i8** %10
br label %29
70: ; preds = %21, %29
ret void
}

LLVM IR (-O2):
@.str = [57 x i8] c"get_config: response to long for buffer, resp_len=%d>>>\0A\00"
@.str.1 = [43 x i8] c"get_config: response length too short: %d\0A\00"
@.str.2 = [68 x i8] c" get_config: additional length [%d] not a multiple of 4, ignore\0A\00"
define void @decode_get_config(i8* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %7
7: ; preds = %5, %3
%8 = phi i32 [ %1, %5 ], [ %2, %3 ]
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %42
12: ; preds = %7
%13 = add nsw i32 %8, -8
%14 = icmp eq i32 %8, 8
br i1 %14, label %42, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 8
br label %17
17: ; preds = %15, %37
%18 = phi i8* [ %40, %37 ], [ %16, %15 ]
%19 = phi i32 [ %38, %37 ], [ 0, %15 ]
%20 = getelementptr inbounds i8, i8* %18, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = add nuw nsw i32 %22, 4
%24 = and i32 %22, 3
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = tail call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %37
28: ; preds = %17
%29 = load i8, i8* %18
%30 = zext i8 %29 to i32
%31 = shl nuw nsw i32 %30, 8
%32 = getelementptr inbounds i8, i8* %18, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = or i32 %31, %34
%36 = tail call i32 @decode_get_config_feature(i32 %35, i8* %18, i32 %23)
br label %37
37: ; preds = %26, %28
%38 = add nuw nsw i32 %23, %19
%39 = zext i32 %23 to i64
%40 = getelementptr inbounds i8, i8* %18, i64 %39
%41 = icmp slt i32 %38, %13
br i1 %41, label %17, label %42
42: ; preds = %37, %12, %10
ret void
}