#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 */
char *malloc(unsigned int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *printraw_packet(const unsigned char *packet, unsigned int len) {
  unsigned int i = 0, j = 0;
  char *buf, *bptr;
  bptr = buf = malloc((len * 3) + (len >> 4) + 11);
  while (i < len) {
    sprintf(bptr, "%02x ", packet[i++]);
    bptr += 3;
    if (++j == 16) {
      sprintf(bptr++, "\n");
      j = 0;
    }
  }
  bptr = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<printraw_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
imul   $0x3,-0xc(%rbp),%edi
mov    -0xc(%rbp),%eax
shr    $0x4,%eax
add    %eax,%edi
add    $0xb,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11d3 <printraw_packet+0xb3>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x10,%eax
jne    11ce <printraw_packet+0xae>
mov    -0x28(%rbp),%rdi
mov    %rdi,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
movl   $0x0,-0x14(%rbp)
jmp    1159 <printraw_packet+0x39>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printraw_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
lea    (%rbx,%rbx,2),%eax
mov    %esi,%ecx
shr    $0x4,%ecx
lea    (%rcx,%rax,1),%edi
add    $0xb,%edi
call   1030 <malloc@plt>
mov    %rax,(%rsp)
test   %ebx,%ebx
je     119b <printraw_packet+0x7b>
mov    %ebx,%r13d
lea    0xeab(%rip),%r15
xor    %ebp,%ebp
mov    (%rsp),%rbx
xor    %r14d,%r14d
jmp    1172 <printraw_packet+0x52>
movw   $0xa,0x3(%rbx)
add    $0x4,%rbx
xor    %r14d,%r14d
cmp    %rbp,%r13
je     119b <printraw_packet+0x7b>
movzbl (%r12,%rbp,1),%edx
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0x1,%r14d
cmp    $0x10,%r14d
je     1160 <printraw_packet+0x40>
add    $0x3,%rbx
cmp    %rbp,%r13
jne    1172 <printraw_packet+0x52>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @printraw_packet(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = mul i32 %9, 3
%11 = load i32, i32* %4
%12 = lshr i32 %11, 4
%13 = add i32 %10, %12
%14 = add i32 %13, 11
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %7
store i8* %15, i8** %8
br label %16
16: ; preds = %39, %2
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i64 3
store i8* %31, i8** %8
%32 = load i32, i32* %6
%33 = add i32 %32, 1
store i32 %33, i32* %6
%34 = icmp eq i32 %33, 16
br i1 %34, label %35, label %39
35: ; preds = %20
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %39
39: ; preds = %35, %20
br label %16
40: ; preds = %16
store i8* null, i8** %8
%41 = load i8*, i8** %7
ret i8* %41
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
define noalias i8* @printraw_packet(i8* nocapture %0, i32 %1) {
%3 = mul i32 %1, 3
%4 = lshr i32 %1, 4
%5 = add nuw nsw i32 %4, 11
%6 = add i32 %5, %3
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i32 %1, 0
br i1 %8, label %30, label %9
9: ; preds = %2
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %26
%12 = phi i64 [ 0, %9 ], [ %15, %26 ]
%13 = phi i8* [ %7, %9 ], [ %28, %26 ]
%14 = phi i32 [ 0, %9 ], [ %27, %26 ]
%15 = add nuw nsw i64 %12, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %12
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %13, i64 3
%21 = add i32 %14, 1
%22 = icmp eq i32 %21, 16
br i1 %22, label %23, label %26
23: ; preds = %11
%24 = getelementptr inbounds i8, i8* %13, i64 4
%25 = bitcast i8* %20 to i16*
store i16 10, i16* %25
br label %26
26: ; preds = %23, %11
%27 = phi i32 [ 0, %23 ], [ %21, %11 ]
%28 = phi i8* [ %24, %23 ], [ %20, %11 ]
%29 = icmp eq i64 %15, %10
br i1 %29, label %30, label %11
30: ; preds = %26, %2
ret i8* %7
}