#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 uint16_t;

/* Variables and functions */
int bee_pkt_csum(void *, int);
void *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char);
int main() {
  void *data = malloc(4);
  char *tmp = data;
  tmp[0] = 0x01;
  tmp[1] = 0x02;
  tmp[2] = 0x03;
  tmp[3] = 0x04;
  uint16_t csum = bee_pkt_csum(data, 4);
  unsigned char sum[2];
  sum[0] = csum >> 8;
  sum[1] = csum & 0xFF;
  printf("%02X %02X\n", sum[0], sum[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x2,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x3,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0x4,0x3(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <bee_pkt_csum@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x1e(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x1d(%rbp)
mov    -0x1e(%rbp),%al
lea    0xe5d(%rip),%rdi
movzbl %al,%esi
movzbl -0x1d(%rbp),%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x4,%edi
call   1040 <malloc@plt>
movl   $0x4030201,(%rax)
mov    %rax,%rdi
mov    $0x4,%esi
call   1050 <bee_pkt_csum@plt>
movzbl %ah,%esi
movzbl %al,%edx
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%02X %02X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [2 x i8]
store i32 0, i32* %1
%6 = call i8* @malloc(i32 4)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 1, i8* %9
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 2, i8* %11
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 2
store i8 3, i8* %13
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 3
store i8 4, i8* %15
%16 = load i8*, i8** %2
%17 = call i32 @bee_pkt_csum(i8* %16, i32 4)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = ashr i32 %18, 8
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %20, i8* %21
%22 = load i32, i32* %4
%23 = and i32 %22, 255
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %24, i8* %25
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%27 = load i8, i8* %26
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%29 = load i8, i8* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 zeroext %27, i8 zeroext %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"%02X %02X\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
store i8 1, i8* %1
%2 = getelementptr inbounds i8, i8* %1, i64 1
store i8 2, i8* %2
%3 = getelementptr inbounds i8, i8* %1, i64 2
store i8 3, i8* %3
%4 = getelementptr inbounds i8, i8* %1, i64 3
store i8 4, i8* %4
%5 = tail call i32 @bee_pkt_csum(i8* %1, i32 4)
%6 = lshr i32 %5, 8
%7 = trunc i32 %6 to i8
%8 = trunc i32 %5 to i8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 zeroext %7, i8 zeroext %8)
ret i32 0
}