#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 */
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ simptcp_get_ack_num(char *);
int /*<<< orphan*/ simptcp_get_dport(char *);
unsigned char simptcp_get_flags(char *);
unsigned char simptcp_get_head_len(char *);
int /*<<< orphan*/ simptcp_get_seq_num(char *);
int /*<<< orphan*/ simptcp_get_sport(char *);
unsigned int simptcp_get_total_len(char *);
int /*<<< orphan*/ strcat(char *, char *);
void simptcp_print_packet(char *buf) {
  char sflags[12] = "|";
  unsigned char hlen = simptcp_get_head_len(buf);
  unsigned int tlen = simptcp_get_total_len(buf);
  unsigned char flags = simptcp_get_flags(buf);
  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"
         "  ] "
         "Source port: %5hu, Destination port: %5hu, seqnum: %5hu\n "
         "acknum:%5hu, hlen: %3d, flags: %7s, tlen: %5hu\n ",
         simptcp_get_sport(buf), simptcp_get_dport(buf),
         simptcp_get_seq_num(buf), simptcp_get_ack_num(buf), hlen, sflags,
         simptcp_get_total_len(buf));
  if (tlen != hlen) {
    printf("["
           "\033"
           "["
           "1"
           ";"
           "32"
           "m"
           "SIMTCP_PKT"
           "\033"
           "[0m"
           "  ] "
           "DATA: %35s \n",
           (buf + hlen));
  }
}


x86 assembly (clang, -O0):
<simptcp_print_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    0xe5b(%rip),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <simptcp_get_head_len@plt>
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <simptcp_get_total_len@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <simptcp_get_flags@plt>
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    11f9 <simptcp_print_packet+0x69>
lea    -0x14(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <strcat@plt>
jmp    1209 <simptcp_print_packet+0x79>
lea    -0x14(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1080 <strcat@plt>
movzbl -0x1d(%rbp),%eax
and    $0x2,%eax
cmp    $0x2,%eax
jne    122e <simptcp_print_packet+0x9e>
lea    -0x14(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1080 <strcat@plt>
jmp    123e <simptcp_print_packet+0xae>
lea    -0x14(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1080 <strcat@plt>
movzbl -0x1d(%rbp),%eax
and    $0x8,%eax
cmp    $0x8,%eax
jne    1263 <simptcp_print_packet+0xd3>
lea    -0x14(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   1080 <strcat@plt>
jmp    1273 <simptcp_print_packet+0xe3>
lea    -0x14(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <simptcp_get_sport@plt>
cltq
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <simptcp_get_dport@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <simptcp_get_seq_num@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <simptcp_get_ack_num@plt>
mov    %eax,-0x30(%rbp)
movzbl -0x15(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <simptcp_get_total_len@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x28(%rbp),%r10
lea    0xd3d(%rip),%rdi
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
movzbl -0x15(%rbp),%ecx
cmp    %ecx,%eax
je     1314 <simptcp_print_packet+0x184>
mov    -0x8(%rbp),%rsi
movzbl -0x15(%rbp),%eax
cltq
add    %rax,%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simptcp_print_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbp
movl   $0x0,0x10(%rsp)
movq   $0x7c,0x8(%rsp)
call   10a0 <simptcp_get_head_len@plt>
mov    %al,0x3(%rsp)
mov    %rbp,%rdi
call   1060 <simptcp_get_total_len@plt>
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
call   1050 <simptcp_get_flags@plt>
mov    %eax,%ebx
test   $0x1,%al
lea    0xe35(%rip),%r14
lea    0xe2b(%rip),%rsi
cmove  %r14,%rsi
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1080 <strcat@plt>
test   $0x2,%bl
lea    0xe16(%rip),%rsi
cmove  %r14,%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
test   $0x8,%bl
lea    0xe03(%rip),%rsi
cmove  %r14,%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %rbp,%rdi
call   10b0 <simptcp_get_sport@plt>
movslq %eax,%rbx
mov    %rbp,%rdi
call   1040 <simptcp_get_dport@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1090 <simptcp_get_seq_num@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1070 <simptcp_get_ack_num@plt>
mov    %eax,%r12d
movzbl 0x3(%rsp),%r13d
mov    %rbp,%rdi
call   1060 <simptcp_get_total_len@plt>
mov    %eax,%r10d
lea    0xdb6(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
push   %r10
lea    0x10(%rsp),%rbx
push   %rbx
call   1030 <printf@plt>
add    $0x10,%rsp
cmp    %r13d,0x4(%rsp)
je     129f <simptcp_print_packet+0x10f>
add    %r13,%rbp
lea    0xe07(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.simptcp_print_packet.sflags = [12 x i8] c"|\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"S|\00"
@.str.1 = [3 x i8] c" |\00"
@.str.2 = [3 x i8] c"A|\00"
@.str.3 = [3 x i8] c"R|\00"
@.str.4 = [132 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] Source port: %5hu, Destination port: %5hu, seqnum: %5hu\0A acknum:%5hu, hlen: %3d, flags: %7s, tlen: %5hu\0A \00"
@.str.5 = [39 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] DATA: %35s \0A\00"
define void @simptcp_print_packet(i8* %0) {
%2 = alloca i8*
%3 = alloca [12 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
%7 = bitcast [12 x i8]* %3 to i8*
%8 = load i8*, i8** %2
%9 = call zeroext i8 @simptcp_get_head_len(i8* %8)
store i8 %9, i8* %4
%10 = load i8*, i8** %2
%11 = call i32 @simptcp_get_total_len(i8* %10)
store i32 %11, i32* %5
%12 = load i8*, i8** %2
%13 = call zeroext i8 @simptcp_get_flags(i8* %12)
store i8 %13, i8* %6
%14 = load i8, i8* %6
%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 i32 @strcat(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, 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 i32 @strcat(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i8, i8* %6
%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 i32 @strcat(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, 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 i32 @strcat(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
%36 = load i8, i8* %6
%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 i32 @strcat(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, 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 i32 @strcat(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %2
%48 = call i32 @simptcp_get_sport(i8* %47)
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
%51 = load i8*, i8** %2
%52 = call i32 @simptcp_get_dport(i8* %51)
%53 = load i8*, i8** %2
%54 = call i32 @simptcp_get_seq_num(i8* %53)
%55 = load i8*, i8** %2
%56 = call i32 @simptcp_get_ack_num(i8* %55)
%57 = load i8, i8* %4
%58 = zext i8 %57 to i32
%59 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%60 = load i8*, i8** %2
%61 = call i32 @simptcp_get_total_len(i8* %60)
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.4, i64 0, i64 0), i8* %50, i32 %52, i32 %54, i32 %56, i32 %58, i8* %59, i32 %61)
%63 = load i32, i32* %5
%64 = load i8, i8* %4
%65 = zext i8 %64 to i32
%66 = icmp ne i32 %63, %65
br i1 %66, label %67, label %74
67: ; preds = %46
%68 = load i8*, i8** %2
%69 = load i8, i8* %4
%70 = zext i8 %69 to i32
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %67, %46
ret void
}

LLVM IR (-O2):
@__const.simptcp_print_packet.sflags = [12 x i8] c"|\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"S|\00"
@.str.1 = [3 x i8] c" |\00"
@.str.2 = [3 x i8] c"A|\00"
@.str.3 = [3 x i8] c"R|\00"
@.str.4 = [132 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] Source port: %5hu, Destination port: %5hu, seqnum: %5hu\0A acknum:%5hu, hlen: %3d, flags: %7s, tlen: %5hu\0A \00"
@.str.5 = [39 x i8] c"[\1B[1;32mSIMTCP_PKT\1B[0m ] DATA: %35s \0A\00"
define void @simptcp_print_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 zeroext i8 @simptcp_get_head_len(i8* %0)
%5 = tail call i32 @simptcp_get_total_len(i8* %0)
%6 = tail call zeroext i8 @simptcp_get_flags(i8* %0)
%7 = zext i8 %6 to i32
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%11 = call i32 @strcat(i8* %3, i8* %10)
%12 = and i32 %7, 2
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%15 = call i32 @strcat(i8* %3, i8* %14)
%16 = and i32 %7, 8
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%19 = call i32 @strcat(i8* %3, i8* %18)
%20 = call i32 @simptcp_get_sport(i8* %0)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @simptcp_get_dport(i8* %0)
%24 = call i32 @simptcp_get_seq_num(i8* %0)
%25 = call i32 @simptcp_get_ack_num(i8* %0)
%26 = zext i8 %4 to i32
%27 = call i32 @simptcp_get_total_len(i8* %0)
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %23, i32 %24, i32 %25, i32 %26, i8* %3, i32 %27)
%29 = icmp eq i32 %5, %26
br i1 %29, label %34, label %30
30: ; preds = %1
%31 = zext i8 %4 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %1
ret void
}