#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 */
scalar_t__ framecpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, unsigned char);
void frame(unsigned char dst[6], unsigned char src[6], unsigned count,
           unsigned char buf[1500]) {
  unsigned char packet_type[4] = {0xa, 0xb, 0xc, 0xd};
  unsigned char checksum[4] = {0x0, 0x0, 0x0, 0x0};
  unsigned char frame[6 + 6 + 4 + 1500 + 4];
  unsigned i, ptr = 0;
  ptr += framecpy(frame + ptr, dst, 6);
  ptr += framecpy(frame + ptr, src, 6);
  ptr += framecpy(frame + ptr, packet_type, 4);
  ptr += framecpy(frame + ptr, buf, count);
  ptr += framecpy(frame + ptr, checksum, 4);
  for (i = 0; i < ptr; i++) {
    printf("%02x", frame[i]);
  }
}


x86 assembly (clang, -O0):
<frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0xeb0(%rip),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x0,-0x628(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x628(%rbp),%eax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x6,%edx
call   1030 <framecpy@plt>
mov    %rax,%rcx
mov    -0x628(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x628(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x628(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1030 <framecpy@plt>
mov    %rax,%rcx
mov    -0x628(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x628(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x628(%rbp),%eax
add    %rax,%rdi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <framecpy@plt>
mov    %rax,%rcx
mov    -0x628(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x628(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x628(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <framecpy@plt>
mov    %rax,%rcx
mov    -0x628(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x628(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x628(%rbp),%eax
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <framecpy@plt>
mov    %rax,%rcx
mov    -0x628(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x628(%rbp)
movl   $0x0,-0x624(%rbp)
mov    -0x624(%rbp),%eax
cmp    -0x628(%rbp),%eax
jae    12a5 <frame+0x175>
mov    -0x624(%rbp),%eax
lea    0xd80(%rip),%rdi
movzbl -0x620(%rbp,%rax,1),%esi
ff
call   1040 <printf@plt>
mov    -0x624(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x624(%rbp)
jmp    1265 <frame+0x135>
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x608,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rsi
movl   $0xd0c0b0a,0xc(%rsp)
0d
movl   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x6,%edx
call   1030 <framecpy@plt>
mov    %rax,%rbp
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <framecpy@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <framecpy@plt>
mov    %rax,%rbp
add    %rbx,%rbp
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <framecpy@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1030 <framecpy@plt>
add    %rbx,%rax
test   %eax,%eax
je     11f6 <frame+0xd6>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0xe23(%rip),%r14
nopl   (%rax)
movzbl 0x10(%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <frame+0xc0>
add    $0x608,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.frame.packet_type = [4 x i8] c"\0A\0B\0C\0D"
@.str = [5 x i8] c"%02x\00"
define void @frame(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [4 x i8]
%10 = alloca [4 x i8]
%11 = alloca [1520 x i8]
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%14 = bitcast [4 x i8]* %9 to i8*
%15 = bitcast [4 x i8]* %10 to i8*
store i32 0, i32* %13
%16 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 0
%17 = load i32, i32* %13
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8*, i8** %5
%21 = call i64 @framecpy(i8* %19, i8* %20, i32 6)
%22 = load i32, i32* %13
%23 = zext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %13
%26 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 0
%27 = load i32, i32* %13
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8*, i8** %6
%31 = call i64 @framecpy(i8* %29, i8* %30, i32 6)
%32 = load i32, i32* %13
%33 = zext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %13
%36 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 0
%37 = load i32, i32* %13
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%41 = call i64 @framecpy(i8* %39, i8* %40, i32 4)
%42 = load i32, i32* %13
%43 = zext i32 %42 to i64
%44 = add nsw i64 %43, %41
%45 = trunc i64 %44 to i32
store i32 %45, i32* %13
%46 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 0
%47 = load i32, i32* %13
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8*, i8** %8
%51 = load i32, i32* %7
%52 = call i64 @framecpy(i8* %49, i8* %50, i32 %51)
%53 = load i32, i32* %13
%54 = zext i32 %53 to i64
%55 = add nsw i64 %54, %52
%56 = trunc i64 %55 to i32
store i32 %56, i32* %13
%57 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 0
%58 = load i32, i32* %13
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%62 = call i64 @framecpy(i8* %60, i8* %61, i32 4)
%63 = load i32, i32* %13
%64 = zext i32 %63 to i64
%65 = add nsw i64 %64, %62
%66 = trunc i64 %65 to i32
store i32 %66, i32* %13
store i32 0, i32* %12
br label %67
67: ; preds = %77, %4
%68 = load i32, i32* %12
%69 = load i32, i32* %13
%70 = icmp ult i32 %68, %69
br i1 %70, label %71, label %80
71: ; preds = %67
%72 = load i32, i32* %12
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds [1520 x i8], [1520 x i8]* %11, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %75)
br label %77
77: ; preds = %71
%78 = load i32, i32* %12
%79 = add i32 %78, 1
store i32 %79, i32* %12
br label %67
80: ; preds = %67
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @frame(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1520 x i8]
%8 = bitcast i32* %5 to i8*
store i32 218893066, i32* %5
%9 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%10 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 0
%11 = call i64 @framecpy(i8* %10, i8* %0, i32 6)
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 %12
%14 = call i64 @framecpy(i8* %13, i8* %1, i32 6)
%15 = add i64 %14, %11
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 %16
%18 = call i64 @framecpy(i8* %17, i8* %8, i32 4)
%19 = add i64 %15, %18
%20 = and i64 %19, 4294967295
%21 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 %20
%22 = call i64 @framecpy(i8* %21, i8* %3, i32 %2)
%23 = add i64 %19, %22
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 %24
%26 = call i64 @framecpy(i8* %25, i8* %9, i32 4)
%27 = add i64 %23, %26
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %4
%31 = and i64 %27, 4294967295
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %37, %32 ]
%34 = getelementptr inbounds [1520 x i8], [1520 x i8]* %7, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %31
br i1 %38, label %39, label %32
39: ; preds = %32, %4
ret void
}