#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 atoi_len(char const *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int packet_unpack_word_resp(const char *packet, char *explain) {
  int result;
  int explain_len;
  int len = (4 + 2);
  result = atoi_len(packet + len, 2);
  len += 2;
  if (0 == result) {
    explain_len = atoi_len(packet, 4);
    memcpy(explain, packet + len, explain_len);
    explain[explain_len] = '\0';
  }
  return result;
}


x86 assembly (clang, -O0):
<packet_unpack_word_resp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x6,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    $0x2,%esi
call   1040 <atoi_len@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1197 <packet_unpack_word_resp+0x77>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1040 <atoi_len@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_unpack_word_resp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x6,%rdi
mov    $0x2,%esi
call   1040 <atoi_len@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    116a <packet_unpack_word_resp+0x4a>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <atoi_len@plt>
mov    %eax,%r15d
add    $0x8,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @packet_unpack_word_resp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 6, i32* %7
%8 = load i8*, i8** %3
%9 = load i32, i32* %7
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = call i32 @atoi_len(i8* %11, i32 2)
store i32 %12, i32* %5
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 2
store i32 %14, i32* %7
%15 = load i32, i32* %5
%16 = icmp eq i32 0, %15
br i1 %16, label %17, label %31
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @atoi_len(i8* %18, i32 4)
store i32 %19, i32* %6
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %6
%26 = call i32 @memcpy(i8* %20, i8* %24, i32 %25)
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %17, %2
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @packet_unpack_word_resp(i8* %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 6
%4 = tail call i32 @atoi_len(i8* %3, i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = tail call i32 @atoi_len(i8* %0, i32 4)
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = tail call i32 @memcpy(i8* %1, i8* %8, i32 %7)
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %6, %2
ret i32 %4
}