#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 */
typedef int uint8_t;
typedef int uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void fprint_uint8_table(FILE *outfile, uint8_t *table, uint64_t length,
                        char *header, char *footer, char *begin_line) {
  int i;
  fprintf(outfile, "%s", header);
  for (i = 0; i < length - 1; i++) {
    if ((i & 7) == 0)
      fprintf(outfile, "\n%s", begin_line);
    else
      fprintf(outfile, " ");
    fprintf(outfile, "0x%02x,", table[i]);
  }
  if ((i & 7) == 0)
    fprintf(outfile, "\n%s", begin_line);
  else
    fprintf(outfile, " ");
  fprintf(outfile, "0x%02x", table[i]);
  fprintf(outfile, "%s", footer);
}


x86 assembly (clang, -O0):
<fprint_uint8_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xec3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c4 <fprint_uint8_table+0xb4>
mov    -0x34(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    1187 <fprint_uint8_table+0x77>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1199 <fprint_uint8_table+0x89>
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114c <fprint_uint8_table+0x3c>
mov    -0x34(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11ee <fprint_uint8_table+0xde>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1200 <fprint_uint8_table+0xf0>
mov    -0x8(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_uint8_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r12
mov    %r8,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rcx,%rdi
mov    %rbx,%rsi
call   1030 <fputs@plt>
xor    %r13d,%r13d
cmp    $0x2,%ebp
jl     11e9 <fprint_uint8_table+0xb9>
mov    %r14,0x10(%rsp)
add    $0xffffffff,%ebp
mov    %ebp,0xc(%rsp)
mov    %ebp,%r13d
lea    0xe8b(%rip),%r14
xor    %ebp,%ebp
jmp    11a7 <fprint_uint8_table+0x77>
nopl   (%rax)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    (%r15,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11c3 <fprint_uint8_table+0x93>
test   $0x7,%bpl
jne    1180 <fprint_uint8_table+0x50>
mov    %rbx,%rdi
lea    0xe49(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    118d <fprint_uint8_table+0x5d>
mov    0xc(%rsp),%ebp
test   $0x7,%bpl
je     11e1 <fprint_uint8_table+0xb1>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x10(%rsp),%r14
jmp    1200 <fprint_uint8_table+0xd0>
mov    %ebp,%r13d
mov    0x10(%rsp),%r14
lea    0xe10(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13d,%ebp
mov    %ebp,%eax
mov    (%r15,%rax,4),%edx
lea    0xdff(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputs@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"\0A%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [8 x i8] c"0x%02x,\00"
@.str.4 = [7 x i8] c"0x%02x\00"
define void @fprint_uint8_table(i32* %0, i32* %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%14 = load i32*, i32** %7
%15 = load i8*, i8** %10
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 0, i32* %13
br label %17
17: ; preds = %41, %6
%18 = load i32, i32* %13
%19 = load i32, i32* %9
%20 = sub nsw i32 %19, 1
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %44
22: ; preds = %17
%23 = load i32, i32* %13
%24 = and i32 %23, 7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32*, i32** %7
%28 = load i8*, i8** %12
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %33
30: ; preds = %22
%31 = load i32*, i32** %7
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %30, %26
%34 = load i32*, i32** %7
%35 = load i32*, i32** %8
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %13
%43 = add nsw i32 %42, 1
store i32 %43, i32* %13
br label %17
44: ; preds = %17
%45 = load i32, i32* %13
%46 = and i32 %45, 7
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32*, i32** %7
%50 = load i8*, i8** %12
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %50)
br label %55
52: ; preds = %44
%53 = load i32*, i32** %7
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %52, %48
%56 = load i32*, i32** %7
%57 = load i32*, i32** %8
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %7
%64 = load i8*, i8** %11
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %64)
ret void
}

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