#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*/ fputc(unsigned char const, int /*<<< orphan*/);
scalar_t__ isprint(unsigned char const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void print_payload(const char *const prefix, const unsigned char *payload,
                   const int n) {
  const int end = n < 1024 ? n : 1024;
  int i = 0;
  printf("%s %d character%s", prefix, n, n == 1 ? "" : "s");
  if (end != n)
    printf(" (first %d shown)", end);
  printf("\n  \"");
  for (; i != end; ++i) {
    const unsigned char c = payload[i];
    if (isprint(c))
      fputc(c, stdout);
    else
      printf("\\x%02x", c);
  }
  printf("\"\n");
}


x86 assembly (clang, -O0):
<print_payload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    115b <print_payload+0x2b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <print_payload+0x38>
mov    $0x400,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <print_payload+0x38>
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%edi
lea    0xe8a(%rip),%rcx
lea    0xea5(%rip),%rax
cmp    $0x1,%edi
cmove  %rax,%rcx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11bf <print_payload+0x8f>
mov    -0x18(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1238 <print_payload+0x108>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1213 <print_payload+0xe3>
mov    -0x1d(%rbp),%al
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1040 <fputc@plt>
jmp    1225 <print_payload+0xf5>
movzbl -0x1d(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122a <print_payload+0xfa>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <print_payload+0x9d>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_payload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rsi
cmp    $0x400,%edx
mov    $0x400,%r14d
cmovl  %edx,%r14d
cmp    $0x1,%edx
lea    0xebb(%rip),%rax
lea    0xe9c(%rip),%rcx
cmove  %rax,%rcx
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x401,%ebp
jl     119f <print_payload+0x5f>
lea    0xe7d(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     1203 <print_payload+0xc3>
mov    %r14d,%r13d
lea    0xe6d(%rip),%r14
mov    0x2e1d(%rip),%r12
xor    %ebx,%ebx
jmp    11e5 <print_payload+0xa5>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1203 <print_payload+0xc3>
movzbl (%r15,%rbx,1),%ebp
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11d0 <print_payload+0x90>
mov    (%r12),%esi
mov    %ebp,%edi
call   1050 <fputc@plt>
jmp    11dc <print_payload+0x9c>
lea    0xe1d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"%s %d character%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [18 x i8] c" (first %d shown)\00"
@.str.4 = [5 x i8] c"\0A \22\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"\\x%02x\00"
@.str.6 = [3 x i8] c"\22\0A\00"
define void @print_payload(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 1024
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32, i32* %6
br label %15
14: ; preds = %3
br label %15
15: ; preds = %14, %12
%16 = phi i32 [ %13, %12 ], [ 1024, %14 ]
store i32 %16, i32* %7
store i32 0, i32* %8
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18, i8* %22)
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %15
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %54, %30
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %57
36: ; preds = %32
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %9
%42 = load i8, i8* %9
%43 = call i64 @isprint(i8 zeroext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load i8, i8* %9
%47 = load i32, i32* @stdout
%48 = call i32 @fputc(i8 zeroext %46, i32 %47)
br label %53
49: ; preds = %36
%50 = load i8, i8* %9
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %49, %45
br label %54
54: ; preds = %53
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %32
57: ; preds = %32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%s %d character%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [18 x i8] c" (first %d shown)\00"
@.str.4 = [5 x i8] c"\0A \22\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"\\x%02x\00"
@str = [2 x i8] c"\22\00"
define void @print_payload(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp slt i32 %2, 1024
%5 = select i1 %4, i32 %2, i32 1024
%6 = icmp eq i32 %2, 1
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2, i8* %7)
%9 = icmp slt i32 %2, 1025
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %10, %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32 %5, 0
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = zext i32 %5 to i64
br label %17
17: ; preds = %15, %29
%18 = phi i64 [ 0, %15 ], [ %30, %29 ]
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = tail call i64 @isprint(i8 zeroext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = load i32, i32* @stdout
%25 = tail call i32 @fputc(i8 zeroext %20, i32 %24)
br label %29
26: ; preds = %17
%27 = zext i8 %20 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %23
%30 = add nuw nsw i64 %18, 1
%31 = icmp eq i64 %30, %16
br i1 %31, label %32, label %17
32: ; preds = %29, %12
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}