#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 */
struct wimax_dev_status {
  int dummy;
};

/* Variables and functions */
int process_E_response(struct wimax_dev_status *, unsigned char const *, int);
int process_P_response(struct wimax_dev_status *, unsigned char const *, int);
int process_config_response(struct wimax_dev_status *, unsigned char const *,
                            int);
int process_data_response(struct wimax_dev_status *, unsigned char const *,
                          int);
int /*<<< orphan*/ wmlog_msg(int, char *, ...);
int process_response(struct wimax_dev_status *dev, const unsigned char *buf,
                     int len) {
  int check_len;
  if (len < 4) {
    wmlog_msg(1, "short read");
    return -1;
  }
  if (buf[0] != 0x57) {
    wmlog_msg(1, "bad header");
    return -1;
  }
  check_len = 4 + buf[2] + (buf[3] << 8);
  if (buf[1] == 0x43 || buf[1] == 0x44) {
    check_len += 2;
  }
  if (check_len != len) {
    wmlog_msg(1, "bad length: %02x instead of %02x", check_len, len);
    return -1;
  }
  switch (buf[1]) {
  case 0x43:
    return process_config_response(dev, buf, len);
  case 0x44:
    return process_data_response(dev, buf, len);
  case 0x45:
    return process_E_response(dev, buf, len);
  case 0x50:
    return process_P_response(dev, buf, len);
  default:
    wmlog_msg(1, "bad response type: %02x", buf[1]);
    return -1;
  }
}


x86 assembly (clang, -O0):
<process_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    118c <process_response+0x3c>
mov    $0x1,%edi
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1070 <wmlog_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x57,%eax
je     11bb <process_response+0x6b>
mov    $0x1,%edi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1070 <wmlog_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x18(%rbp),%rax
movzbl 0x2(%rax),%eax
add    $0x4,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x43,%eax
je     11f8 <process_response+0xa8>
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x44,%eax
jne    1201 <process_response+0xb1>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1232 <process_response+0xe2>
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1070 <wmlog_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
add    $0xffffffbd,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xd,%eax
ja     12c0 <process_response+0x170>
mov    -0x28(%rbp),%rax
lea    0xda9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <process_config_response@plt>
mov    %eax,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <process_data_response@plt>
mov    %eax,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <process_E_response@plt>
mov    %eax,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <process_P_response@plt>
mov    %eax,-0x4(%rbp)
jmp    12e2 <process_response+0x192>
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    $0x1,%edi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1070 <wmlog_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_response>:
push   %rax
cmp    $0x3,%edx
jg     115f <process_response+0xf>
lea    0xedb(%rip),%rsi
jmp    11b0 <process_response+0x60>
cmpb   $0x57,(%rsi)
jne    11a9 <process_response+0x59>
mov    %edx,%ecx
movzwl 0x2(%rsi),%r8d
movzbl 0x1(%rsi),%edx
lea    -0x43(%rdx),%r9d
xor    %eax,%eax
cmp    $0x2,%r9b
setb   %al
lea    (%r8,%rax,2),%eax
add    $0x4,%eax
cmp    %ecx,%eax
jne    11c3 <process_response+0x73>
lea    -0x43(%rdx),%eax
cmp    $0xd,%al
ja     11ea <process_response+0x9a>
movzbl %al,%eax
lea    0xe68(%rip),%r8
movslq (%r8,%rax,4),%rax
add    %r8,%rax
jmp    *%rax
mov    %ecx,%edx
pop    %rax
jmp    1050 <process_config_response@plt>
lea    0xe93(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <wmlog_msg@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xe84(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <wmlog_msg@plt>
jmp    11bc <process_response+0x6c>
mov    %ecx,%edx
pop    %rax
jmp    1040 <process_data_response@plt>
mov    %ecx,%edx
pop    %rax
jmp    1060 <process_E_response@plt>
lea    0xe7e(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <wmlog_msg@plt>
jmp    11bc <process_response+0x6c>
mov    %ecx,%edx
pop    %rax
jmp    1030 <process_P_response@plt>

LLVM IR (-O0):
%struct.wimax_dev_status = type { i32 }
@.str = [11 x i8] c"short read\00"
@.str.1 = [11 x i8] c"bad header\00"
@.str.2 = [33 x i8] c"bad length: %02x instead of %02x\00"
@.str.3 = [24 x i8] c"bad response type: %02x\00"
define i32 @process_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.wimax_dev_status*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.wimax_dev_status* %0, %struct.wimax_dev_status** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %86
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 87
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %86
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = add nsw i32 4, %25
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = shl i32 %30, 8
%32 = add nsw i32 %26, %31
store i32 %32, i32* %8
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp eq i32 %36, 67
br i1 %37, label %44, label %38
38: ; preds = %21
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, 68
br i1 %43, label %44, label %47
44: ; preds = %38, %21
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 2
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %38
%48 = load i32, i32* %8
%49 = load i32, i32* %7
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %53)
store i32 -1, i32* %4
br label %86
55: ; preds = %47
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
switch i32 %59, label %80 [
i32 67, label %60
i32 68, label %65
i32 69, label %70
i32 80, label %75
]
60: ; preds = %55
%61 = load %struct.wimax_dev_status*, %struct.wimax_dev_status** %5
%62 = load i8*, i8** %6
%63 = load i32, i32* %7
%64 = call i32 @process_config_response(%struct.wimax_dev_status* %61, i8* %62, i32 %63)
store i32 %64, i32* %4
br label %86
65: ; preds = %55
%66 = load %struct.wimax_dev_status*, %struct.wimax_dev_status** %5
%67 = load i8*, i8** %6
%68 = load i32, i32* %7
%69 = call i32 @process_data_response(%struct.wimax_dev_status* %66, i8* %67, i32 %68)
store i32 %69, i32* %4
br label %86
70: ; preds = %55
%71 = load %struct.wimax_dev_status*, %struct.wimax_dev_status** %5
%72 = load i8*, i8** %6
%73 = load i32, i32* %7
%74 = call i32 @process_E_response(%struct.wimax_dev_status* %71, i8* %72, i32 %73)
store i32 %74, i32* %4
br label %86
75: ; preds = %55
%76 = load %struct.wimax_dev_status*, %struct.wimax_dev_status** %5
%77 = load i8*, i8** %6
%78 = load i32, i32* %7
%79 = call i32 @process_P_response(%struct.wimax_dev_status* %76, i8* %77, i32 %78)
store i32 %79, i32* %4
br label %86
80: ; preds = %55
%81 = load i8*, i8** %6
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %84)
store i32 -1, i32* %4
br label %86
86: ; preds = %80, %75, %70, %65, %60, %51, %19, %11
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
%struct.wimax_dev_status = type { i32 }
@.str = [11 x i8] c"short read\00"
@.str.1 = [11 x i8] c"bad header\00"
@.str.2 = [33 x i8] c"bad length: %02x instead of %02x\00"
@.str.3 = [24 x i8] c"bad response type: %02x\00"
define i32 @process_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2) {
%4 = icmp slt i32 %2, 4
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %43
7: ; preds = %3
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 87
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %43
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %1, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = add nuw nsw i32 %15, 4
%17 = getelementptr inbounds i8, i8* %1, i64 3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = shl nuw nsw i32 %19, 8
%21 = add nuw nsw i32 %16, %20
%22 = getelementptr inbounds i8, i8* %1, i64 1
%23 = load i8, i8* %22
%24 = add i8 %23, -67
%25 = icmp ult i8 %24, 2
%26 = add nuw nsw i32 %21, 2
%27 = select i1 %25, i32 %26, i32 %21
%28 = icmp eq i32 %27, %2
br i1 %28, label %31, label %29
29: ; preds = %12
%30 = tail call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %2)
br label %43
31: ; preds = %12
switch i8 %23, label %40 [
i8 67, label %32
i8 68, label %34
i8 69, label %36
i8 80, label %38
]
32: ; preds = %31
%33 = tail call i32 @process_config_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2)
br label %43
34: ; preds = %31
%35 = tail call i32 @process_data_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2)
br label %43
36: ; preds = %31
%37 = tail call i32 @process_E_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2)
br label %43
38: ; preds = %31
%39 = tail call i32 @process_P_response(%struct.wimax_dev_status* %0, i8* %1, i32 %2)
br label %43
40: ; preds = %31
%41 = zext i8 %23 to i32
%42 = tail call i32 (i32, i8*, ...) @wmlog_msg(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40, %38, %36, %34, %32, %29, %10, %5
%44 = phi i32 [ -1, %5 ], [ -1, %10 ], [ -1, %29 ], [ -1, %40 ], [ %39, %38 ], [ %37, %36 ], [ %35, %34 ], [ %33, %32 ]
ret i32 %44
}