#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__ isascii(unsigned char);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
void print_packet(unsigned char *s, int l) {
  int i, cc;
  cc = 0;
  for (i = 0; i < l; i++) {
    if (isprint(s[i]) && isascii(s[i])) {
      if (s[i] == '\\') {
        printf("\\\\");
        cc += 2;
      } else {
        printf("%c", s[i]);
        cc++;
      }
    } else {
      printf("\\%02X", s[i]);
      cc += 3;
      if (s[i] == '\n') {
        printf("\n");
        cc = 0;
      }
    }
    if (cc > 80) {
      printf("\n");
      cc = 0;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126c <print_packet+0x13c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11e8 <print_packet+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isascii@plt>
cmp    $0x0,%rax
je     11e8 <print_packet+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11c0 <print_packet+0x90>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11e3 <print_packet+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <print_packet+0x10a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1235 <print_packet+0x105>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    123a <print_packet+0x10a>
cmpl   $0x50,-0x14(%rbp)
jle    1259 <print_packet+0x129>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    125e <print_packet+0x12e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <print_packet+0x1d>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1208 <print_packet+0xc8>
mov    %rdi,%r13
mov    %esi,%r12d
lea    0xea3(%rip),%r14
lea    0xe99(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1189 <print_packet+0x49>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
je     1208 <print_packet+0xc8>
movzbl 0x0(%r13,%rbx,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     11d0 <print_packet+0x90>
movzbl 0x0(%r13,%rbx,1),%edi
call   1060 <isascii@plt>
test   %rax,%rax
je     11d0 <print_packet+0x90>
movzbl 0x0(%r13,%rbx,1),%edi
cmp    $0x5c,%edi
jne    11f2 <print_packet+0xb2>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x2,%ebp
cmp    $0x51,%ebp
jge    1170 <print_packet+0x30>
jmp    117c <print_packet+0x3c>
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0xa,0x0(%r13,%rbx,1)
je     1170 <print_packet+0x30>
add    $0x3,%ebp
cmp    $0x51,%ebp
jge    1170 <print_packet+0x30>
jmp    117c <print_packet+0x3c>
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    $0x51,%ebp
jge    1170 <print_packet+0x30>
jmp    117c <print_packet+0x3c>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\\\\00"
@.str.2 = [6 x i8] c"\\%02X\00"
define void @print_packet(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %43
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %39
%7 = phi i64 [ 0, %4 ], [ %41, %39 ]
%8 = phi i32 [ 0, %4 ], [ %40, %39 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @isprint(i8 zeroext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %6
%14 = load i8, i8* %9
%15 = tail call i64 @isascii(i8 zeroext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = load i8, i8* %9
%19 = icmp eq i8 %18, 92
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = add nsw i32 %8, 2
br label %34
23: ; preds = %17
%24 = zext i8 %18 to i32
%25 = tail call i32 @putchar(i32 %24)
%26 = add nsw i32 %8, 1
br label %34
27: ; preds = %13, %6
%28 = load i8, i8* %9
%29 = zext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = add nsw i32 %8, 3
%32 = load i8, i8* %9
%33 = icmp eq i8 %32, 10
br i1 %33, label %37, label %34
34: ; preds = %27, %20, %23
%35 = phi i32 [ %22, %20 ], [ %26, %23 ], [ %31, %27 ]
%36 = icmp sgt i32 %35, 80
br i1 %36, label %37, label %39
37: ; preds = %34, %27
%38 = tail call i32 @putchar(i32 10)
br label %39
39: ; preds = %37, %34
%40 = phi i32 [ %35, %34 ], [ 0, %37 ]
%41 = add nuw nsw i64 %7, 1
%42 = icmp eq i64 %41, %5
br i1 %42, label %43, label %6
43: ; preds = %39, %2
%44 = tail call i32 @putchar(i32 10)
ret void
}