void simptcp_lprint_packet(char *buf) {
  char sflags[12] = "|";
  unsigned char hlen = simptcp_get_head_len(buf);
  unsigned char flags = simptcp_get_flags(buf);
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "function %s called\n",
         __func__);
  if ((flags & 0x01) == 0x01)
    strcat(sflags, "S|");
  else
    strcat(sflags, " |");
  if ((flags & 0x02) == 0x02)
    strcat(sflags, "A|");
  else
    strcat(sflags, " |");
  if ((flags & 0x08) == 0x08)
    strcat(sflags, "R|");
  else
    strcat(sflags, " |");
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "+----------------+-----------------+-------------------+\n");
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "| sport : %5hu | dport : %5hu  | seqnum : %5hu |\n",
         simptcp_get_sport(buf), simptcp_get_dport(buf),
         simptcp_get_seq_num(buf));
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "+----------------+-----------------+-------------------+\n");
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "| acknum : %5hu | hlen : %3d  | Flags : %7s|\n",
         simptcp_get_ack_num(buf), hlen, sflags);
  printf("["
         "\033"
         "["
         "1"
         ";"
         "32"
         "m"
         "SIMTCP_PKT"
         "\033"
         "[0m"
         "  ] "
         "+----------------+-----------------+-------------------+\n");
  if (!flags) {
    printf("["
           "\033"
           "["
           "1"
           ";"
           "32"
           "m"
           "SIMTCP_PKT"
           "\033"
           "[0m"
           "  ] "
           "| DATA : %35s           | \n",
           (buf + hlen));
    printf("["
           "\033"
           "["
           "1"
           ";"
           "32"
           "m"
           "SIMTCP_PKT"
           "\033"
           "[0m"
           "  ] "
           "+----------------------------------+-------------------+\n");
  }
}


x86 assembly (clang, -O0):
<simptcp_lprint_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    0xe6b(%rip),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1090 <simptcp_get_head_len@plt>
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <simptcp_get_flags@plt>
mov    %al,-0x16(%rbp)
lea    0xe49(%rip),%rdi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x16(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    11f6 <simptcp_lprint_packet+0x76>
lea    -0x14(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <strcat@plt>
jmp    1206 <simptcp_lprint_packet+0x86>
lea    -0x14(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <strcat@plt>
movzbl -0x16(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    122b <simptcp_lprint_packet+0xab>
lea    -0x14(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1070 <strcat@plt>
jmp    123b <simptcp_lprint_packet+0xbb>
lea    -0x14(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <strcat@plt>
movzbl -0x16(%rbp),%eax
and    $0x8,%eax
cmp    $0x8,%eax
jne    1260 <simptcp_lprint_packet+0xe0>
lea    -0x14(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1070 <strcat@plt>
jmp    1270 <simptcp_lprint_packet+0xf0>
lea    -0x14(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1070 <strcat@plt>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   10a0 <simptcp_get_sport@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1040 <simptcp_get_dport@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1080 <simptcp_get_seq_num@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1060 <simptcp_get_ack_num@plt>
mov    %eax,%esi
movzbl -0x15(%rbp),%edx
lea    -0x14(%rbp),%rcx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpb   $0x0,-0x16(%rbp)
jne    132d <simptcp_lprint_packet+0x1ad>
mov    -0x8(%rbp),%rsi
movzbl -0x15(%rbp),%eax
cltq
add    %rax,%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simptcp_lprint_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r13
movl   $0x0,0x10(%rsp)
movq   $0x7c,0x8(%rsp)
xor    %eax,%eax
call   10a0 <simptcp_get_head_len@plt>
mov    %eax,%r14d
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <simptcp_get_flags@plt>
mov    %eax,%r12d
lea    0xe3c(%rip),%rdi
lea    0xe63(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
add    %rsp,%rax
add    $0x8,%rax
test   $0x1,%r12b
jne    1200 <simptcp_lprint_packet+0x70>
movb   $0x0,0x2(%rax)
movw   $0x7c20,(%rax)
jmp    1209 <simptcp_lprint_packet+0x79>
movb   $0x0,0x2(%rax)
movw   $0x7c53,(%rax)
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
add    %rsp,%rax
add    $0x8,%rax
test   $0x2,%r12b
jne    122b <simptcp_lprint_packet+0x9b>
movb   $0x0,0x2(%rax)
movw   $0x7c20,(%rax)
jmp    1234 <simptcp_lprint_packet+0xa4>
movb   $0x0,0x2(%rax)
movw   $0x7c41,(%rax)
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
add    %rsp,%rax
add    $0x8,%rax
test   $0x8,%r12b
jne    1256 <simptcp_lprint_packet+0xc6>
movb   $0x0,0x2(%rax)
movw   $0x7c20,(%rax)
jmp    125f <simptcp_lprint_packet+0xcf>
movb   $0x0,0x2(%rax)
movw   $0x7c52,(%rax)
lea    0xec0(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   10b0 <simptcp_get_sport@plt>
mov    %eax,%ebp
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <simptcp_get_dport@plt>
mov    %eax,%ebx
mov    %r13,%rdi
xor    %eax,%eax
call   1090 <simptcp_get_seq_num@plt>
lea    0xdc5(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1080 <simptcp_get_ack_num@plt>
movzbl %r14b,%ebp
lea    0xde7(%rip),%rdi
lea    0x8(%rsp),%rcx
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
test   %r12b,%r12b
jne    1300 <simptcp_lprint_packet+0x170>
mov    %ebp,%eax
add    %rax,%r13
lea    0xe06(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.simptcp_lprint_packet.sflags = [12 x i8] c"|\00\00\00\00\00\00\00\00\00\00\00"
@.str = [46 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] function %s called\0A\00"
@__func__.simptcp_lprint_packet = [22 x i8] c"simptcp_lprint_packet\00"
@.str.1 = [3 x i8] c"S|\00"
@.str.2 = [3 x i8] c" |\00"
@.str.3 = [3 x i8] c"A|\00"
@.str.4 = [3 x i8] c"R|\00"
@.str.5 = [84 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] +----------------+-----------------+-------------------+\0A\00"
@.str.6 = [76 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | sport : %5hu | dport : %5hu | seqnum : %5hu |\0A\00"
@.str.7 = [72 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | acknum : %5hu | hlen : %3d | Flags : %7s|\0A\00"
@.str.8 = [54 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | DATA : %35s | \0A\00"
@.str.9 = [84 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] +----------------------------------+-------------------+\0A\00"
define void @simptcp_lprint_packet(i8* %0) {
%2 = alloca i8*
%3 = alloca [12 x i8]
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %2
%6 = bitcast [12 x i8]* %3 to i8*
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_head_len to i32 (i8*, ...)*)(i8* %7)
%9 = trunc i32 %8 to i8
store i8 %9, i8* %4
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_flags to i32 (i8*, ...)*)(i8* %10)
%12 = trunc i32 %11 to i8
store i8 %12, i8* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.simptcp_lprint_packet, i64 0, i64 0))
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = and i32 %15, 1
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%20 = call i8* @strcat(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
21: ; preds = %1
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%23 = call i8* @strcat(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i8, i8* %5
%26 = zext i8 %25 to i32
%27 = and i32 %26, 2
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%31 = call i8* @strcat(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %35
32: ; preds = %24
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%34 = call i8* @strcat(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
%36 = load i8, i8* %5
%37 = zext i8 %36 to i32
%38 = and i32 %37, 8
%39 = icmp eq i32 %38, 8
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%42 = call i8* @strcat(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %46
43: ; preds = %35
%44 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%45 = call i8* @strcat(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %43, %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0))
%48 = load i8*, i8** %2
%49 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_sport to i32 (i8*, ...)*)(i8* %48)
%50 = load i8*, i8** %2
%51 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_dport to i32 (i8*, ...)*)(i8* %50)
%52 = load i8*, i8** %2
%53 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_seq_num to i32 (i8*, ...)*)(i8* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.6, i64 0, i64 0), i32 %49, i32 %51, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0))
%56 = load i8*, i8** %2
%57 = call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_ack_num to i32 (i8*, ...)*)(i8* %56)
%58 = load i8, i8* %4
%59 = zext i8 %58 to i32
%60 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.7, i64 0, i64 0), i32 %57, i32 %59, i8* %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0))
%63 = load i8, i8* %5
%64 = icmp ne i8 %63, 0
br i1 %64, label %73, label %65
65: ; preds = %46
%66 = load i8*, i8** %2
%67 = load i8, i8* %4
%68 = zext i8 %67 to i32
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.9, i64 0, i64 0))
br label %73
73: ; preds = %65, %46
ret void
}

LLVM IR (-O2):
@__const.simptcp_lprint_packet.sflags = [12 x i8] c"|\00\00\00\00\00\00\00\00\00\00\00"
@.str = [46 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] function %s called\0A\00"
@__func__.simptcp_lprint_packet = [22 x i8] c"simptcp_lprint_packet\00"
@.str.1 = [3 x i8] c"S|\00"
@.str.2 = [3 x i8] c" |\00"
@.str.3 = [3 x i8] c"A|\00"
@.str.4 = [3 x i8] c"R|\00"
@.str.6 = [76 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | sport : %5hu | dport : %5hu | seqnum : %5hu |\0A\00"
@.str.7 = [72 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | acknum : %5hu | hlen : %3d | Flags : %7s|\0A\00"
@.str.8 = [54 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] | DATA : %35s | \0A\00"
@str.11 = [83 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] +----------------+-----------------+-------------------+\00"
@str.12 = [83 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] +----------------------------------+-------------------+\00"
define void @simptcp_lprint_packet(i8* %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_head_len to i32 (i8*, ...)*)(i8* %0)
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_flags to i32 (i8*, ...)*)(i8* %0)
%6 = trunc i32 %5 to i8
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.simptcp_lprint_packet, i64 0, i64 0))
%8 = and i32 %5, 1
%9 = icmp eq i32 %8, 0
%10 = call i64 @strlen(i8* %3)
%11 = getelementptr [12 x i8], [12 x i8]* %2, i64 0, i64 %10
br i1 %9, label %13, label %12
12: ; preds = %1
br label %14
13: ; preds = %1
br label %14
14: ; preds = %13, %12
%15 = and i32 %5, 2
%16 = icmp eq i32 %15, 0
%17 = call i64 @strlen(i8* %3)
%18 = getelementptr [12 x i8], [12 x i8]* %2, i64 0, i64 %17
br i1 %16, label %20, label %19
19: ; preds = %14
br label %21
20: ; preds = %14
br label %21
21: ; preds = %20, %19
%22 = and i32 %5, 8
%23 = icmp eq i32 %22, 0
%24 = call i64 @strlen(i8* %3)
%25 = getelementptr [12 x i8], [12 x i8]* %2, i64 0, i64 %24
br i1 %23, label %27, label %26
26: ; preds = %21
br label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %26
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.11, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_sport to i32 (i8*, ...)*)(i8* %0)
%31 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_dport to i32 (i8*, ...)*)(i8* %0)
%32 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_seq_num to i32 (i8*, ...)*)(i8* %0)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str.6, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.11, i64 0, i64 0))
%35 = tail call i32 (i8*, ...) bitcast (i32 (...)* @simptcp_get_ack_num to i32 (i8*, ...)*)(i8* %0)
%36 = and i32 %4, 255
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %36, i8* %3)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.11, i64 0, i64 0))
%39 = icmp eq i8 %6, 0
br i1 %39, label %40, label %45
40: ; preds = %28
%41 = zext i32 %36 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %42)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.12, i64 0, i64 0))
br label %45
45: ; preds = %40, %28
ret void
}