#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 */
unsigned short calc_csum(unsigned short *, int);
int /*<<< orphan*/ printf(char *, char *, char *, int, char *, unsigned short);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void dump_packet(char *title, unsigned char *pkt, int bytes,
                 unsigned int tx_rx_flag) {
  static int numSend = 1;
  static int numRecv = 1;
  int num, k;
  char tmp[48];
  unsigned short int cksum;
  num = (tx_rx_flag) ? numSend++ : numRecv++;
  for (k = 0; k < 24; k++)
    sprintf(tmp + k, "%02X", pkt[k]);
  cksum = calc_csum((unsigned short *)pkt, bytes >> 2);
  printf("%s-%s (%06d): %s 0x%04X\n", title, (tx_rx_flag) ? "TX" : "RX", num,
         tmp, cksum);
}


x86 assembly (clang, -O0):
<dump_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1169 <dump_packet+0x39>
mov    0x2ee2(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ed7(%rip)
mov    %eax,-0x58(%rbp)
jmp    117d <dump_packet+0x4d>
mov    0x2ecd(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ec2(%rip)
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x18,-0x20(%rbp)
jge    11c5 <dump_packet+0x95>
lea    -0x50(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe52(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118a <dump_packet+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sar    $0x2,%esi
call   1030 <calc_csum@plt>
mov    %ax,-0x52(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%ecx
lea    0xe3b(%rip),%rdx
lea    0xe31(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x50(%rbp),%r8
lea    0xe03(%rip),%rdi
movzwl -0x52(%rbp),%r9d
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %ecx,%ecx
lea    0x2eed(%rip),%rax
lea    0x2ee2(%rip),%rcx
cmove  %rax,%rcx
lea    0xec0(%rip),%rax
lea    0xeb6(%rip),%r15
cmove  %rax,%r15
mov    (%rcx),%r12d
lea    0x1(%r12),%eax
mov    %eax,(%rcx)
movzbl (%rsi),%edx
lea    0xe80(%rip),%r13
mov    %rsp,%rdi
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x1(%rsp),%rdi
movzbl 0x1(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x2(%rsp),%rdi
movzbl 0x2(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x3(%rsp),%rdi
movzbl 0x3(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x4(%rsp),%rdi
movzbl 0x4(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x5(%rsp),%rdi
movzbl 0x5(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x6(%rsp),%rdi
movzbl 0x6(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x7(%rsp),%rdi
movzbl 0x7(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x8(%rsp),%rdi
movzbl 0x8(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x9(%rsp),%rdi
movzbl 0x9(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xa(%rsp),%rdi
movzbl 0xa(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xb(%rsp),%rdi
movzbl 0xb(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xc(%rsp),%rdi
movzbl 0xc(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xd(%rsp),%rdi
movzbl 0xd(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xe(%rsp),%rdi
movzbl 0xe(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0xf(%rsp),%rdi
movzbl 0xf(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
movzbl 0x10(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x11(%rsp),%rdi
movzbl 0x11(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x12(%rsp),%rdi
movzbl 0x12(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x13(%rsp),%rdi
movzbl 0x13(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x14(%rsp),%rdi
movzbl 0x14(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x15(%rsp),%rdi
movzbl 0x15(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x16(%rsp),%rdi
movzbl 0x16(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
lea    0x17(%rsp),%rdi
movzbl 0x17(%rbx),%edx
mov    %r13,%rsi
call   1050 <sprintf@plt>
sar    $0x2,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <calc_csum@plt>
movzwl %ax,%r9d
lea    0xcdb(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12d,%ecx
mov    %rsp,%r8
call   1040 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@dump_packet.numSend = internal global i32 1
@dump_packet.numRecv = internal global i32 1
@.str = [5 x i8] c"%02X\00"
@.str.1 = [25 x i8] c"%s-%s (%06d): %s 0x%04X\0A\00"
@.str.2 = [3 x i8] c"TX\00"
@.str.3 = [3 x i8] c"RX\00"
define void @dump_packet(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [48 x i8]
%12 = alloca i16
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @dump_packet.numSend
%17 = add nsw i32 %16, 1
store i32 %17, i32* @dump_packet.numSend
br label %21
18: ; preds = %4
%19 = load i32, i32* @dump_packet.numRecv
%20 = add nsw i32 %19, 1
store i32 %20, i32* @dump_packet.numRecv
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ %16, %15 ], [ %19, %18 ]
store i32 %22, i32* %9
store i32 0, i32* %10
br label %23
23: ; preds = %37, %21
%24 = load i32, i32* %10
%25 = icmp slt i32 %24, 24
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = getelementptr inbounds [48 x i8], [48 x i8]* %11, i64 0, i64 0
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %6
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
br label %37
37: ; preds = %26
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %23
40: ; preds = %23
%41 = load i8*, i8** %6
%42 = bitcast i8* %41 to i16*
%43 = load i32, i32* %7
%44 = ashr i32 %43, 2
%45 = call zeroext i16 @calc_csum(i16* %42, i32 %44)
store i16 %45, i16* %12
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%51 = load i32, i32* %9
%52 = getelementptr inbounds [48 x i8], [48 x i8]* %11, i64 0, i64 0
%53 = load i16, i16* %12
%54 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %50, i32 %51, i8* %52, i16 zeroext %53)
ret void
}

LLVM IR (-O2):
@dump_packet.numSend = internal unnamed_addr global i32 1
@dump_packet.numRecv = internal unnamed_addr global i32 1
@.str = [5 x i8] c"%02X\00"
@.str.1 = [25 x i8] c"%s-%s (%06d): %s 0x%04X\0A\00"
@.str.2 = [3 x i8] c"TX\00"
@.str.3 = [3 x i8] c"RX\00"
define void @dump_packet(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [48 x i8]
%6 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %3, 0
%8 = select i1 %7, i32* @dump_packet.numRecv, i32* @dump_packet.numSend
%9 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%10 = load i32, i32* %8
%11 = add nsw i32 %10, 1
store i32 %11, i32* %8
%12 = load i8, i8* %1
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 1
%15 = getelementptr inbounds i8, i8* %1, i64 1
%16 = load i8, i8* %15
%17 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 2
%19 = getelementptr inbounds i8, i8* %1, i64 2
%20 = load i8, i8* %19
%21 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %20)
%22 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 3
%23 = getelementptr inbounds i8, i8* %1, i64 3
%24 = load i8, i8* %23
%25 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 4
%27 = getelementptr inbounds i8, i8* %1, i64 4
%28 = load i8, i8* %27
%29 = call i32 @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %28)
%30 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 5
%31 = getelementptr inbounds i8, i8* %1, i64 5
%32 = load i8, i8* %31
%33 = call i32 @sprintf(i8* %30, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
%34 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 6
%35 = getelementptr inbounds i8, i8* %1, i64 6
%36 = load i8, i8* %35
%37 = call i32 @sprintf(i8* %34, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %36)
%38 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 7
%39 = getelementptr inbounds i8, i8* %1, i64 7
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %38, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %40)
%42 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 8
%43 = getelementptr inbounds i8, i8* %1, i64 8
%44 = load i8, i8* %43
%45 = call i32 @sprintf(i8* %42, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %44)
%46 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 9
%47 = getelementptr inbounds i8, i8* %1, i64 9
%48 = load i8, i8* %47
%49 = call i32 @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %48)
%50 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 10
%51 = getelementptr inbounds i8, i8* %1, i64 10
%52 = load i8, i8* %51
%53 = call i32 @sprintf(i8* %50, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %52)
%54 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 11
%55 = getelementptr inbounds i8, i8* %1, i64 11
%56 = load i8, i8* %55
%57 = call i32 @sprintf(i8* %54, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %56)
%58 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 12
%59 = getelementptr inbounds i8, i8* %1, i64 12
%60 = load i8, i8* %59
%61 = call i32 @sprintf(i8* %58, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %60)
%62 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 13
%63 = getelementptr inbounds i8, i8* %1, i64 13
%64 = load i8, i8* %63
%65 = call i32 @sprintf(i8* %62, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %64)
%66 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 14
%67 = getelementptr inbounds i8, i8* %1, i64 14
%68 = load i8, i8* %67
%69 = call i32 @sprintf(i8* %66, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %68)
%70 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 15
%71 = getelementptr inbounds i8, i8* %1, i64 15
%72 = load i8, i8* %71
%73 = call i32 @sprintf(i8* %70, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %72)
%74 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 16
%75 = getelementptr inbounds i8, i8* %1, i64 16
%76 = load i8, i8* %75
%77 = call i32 @sprintf(i8* %74, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %76)
%78 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 17
%79 = getelementptr inbounds i8, i8* %1, i64 17
%80 = load i8, i8* %79
%81 = call i32 @sprintf(i8* %78, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %80)
%82 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 18
%83 = getelementptr inbounds i8, i8* %1, i64 18
%84 = load i8, i8* %83
%85 = call i32 @sprintf(i8* %82, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %84)
%86 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 19
%87 = getelementptr inbounds i8, i8* %1, i64 19
%88 = load i8, i8* %87
%89 = call i32 @sprintf(i8* %86, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %88)
%90 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 20
%91 = getelementptr inbounds i8, i8* %1, i64 20
%92 = load i8, i8* %91
%93 = call i32 @sprintf(i8* %90, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %92)
%94 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 21
%95 = getelementptr inbounds i8, i8* %1, i64 21
%96 = load i8, i8* %95
%97 = call i32 @sprintf(i8* %94, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %96)
%98 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 22
%99 = getelementptr inbounds i8, i8* %1, i64 22
%100 = load i8, i8* %99
%101 = call i32 @sprintf(i8* %98, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %100)
%102 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 23
%103 = getelementptr inbounds i8, i8* %1, i64 23
%104 = load i8, i8* %103
%105 = call i32 @sprintf(i8* %102, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %104)
%106 = bitcast i8* %1 to i16*
%107 = ashr i32 %2, 2
%108 = tail call zeroext i16 @calc_csum(i16* %106, i32 %107)
%109 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %9, i32 %10, i8* %6, i16 zeroext %108)
ret void
}