#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fatal_err(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
void index_by_pixel(FILE *out, long *line, int length) {
  register int n;
  long *lp;
  char *line_pixels;
  register char *lc;
  if (!(line_pixels = malloc(length)))
    fatal_err((("Could not allocate raster line memory.")));
  for (n = 0, lc = line_pixels, lp = line; n < length; n++)
    *lc++ = (char)*lp++;
  fprintf(out, "\033*b%dW", length);
  fwrite(line_pixels, 1, length, out);
  free(line_pixels);
}


x86 assembly (clang, -O0):
<index_by_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1185 <index_by_pixel+0x35>
lea    0xe80(%rip),%rdi
call   1040 <fatal_err@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11db <index_by_pixel+0x8b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119c <index_by_pixel+0x4c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_by_pixel>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    117c <index_by_pixel+0x2c>
lea    0xe89(%rip),%rdi
call   1040 <fatal_err@plt>
test   %r12d,%r12d
jle    120f <index_by_pixel+0xbf>
lea    -0x1(%r12),%eax
cmp    $0x7,%eax
jae    1194 <index_by_pixel+0x44>
mov    %r15,%rax
jmp    11e3 <index_by_pixel+0x93>
mov    %r12d,%ecx
and    $0xfffffff8,%ecx
mov    %r15,%rax
nopl   (%rax)
movzbl (%rbx),%edx
mov    %dl,(%rax)
movzbl 0x8(%rbx),%edx
mov    %dl,0x1(%rax)
movzbl 0x10(%rbx),%edx
mov    %dl,0x2(%rax)
movzbl 0x18(%rbx),%edx
mov    %dl,0x3(%rax)
movzbl 0x20(%rbx),%edx
mov    %dl,0x4(%rax)
movzbl 0x28(%rbx),%edx
mov    %dl,0x5(%rax)
movzbl 0x30(%rbx),%edx
mov    %dl,0x6(%rax)
movzbl 0x38(%rbx),%edx
add    $0x40,%rbx
mov    %dl,0x7(%rax)
add    $0x8,%rax
add    $0xfffffff8,%ecx
jne    11a0 <index_by_pixel+0x50>
test   $0x7,%r12b
je     120f <index_by_pixel+0xbf>
mov    %r12d,%esi
and    $0x7,%esi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rdx,8),%ecx
mov    %cl,(%rax,%rdx,1)
add    $0x1,%rdx
cmp    %edx,%esi
jne    1200 <index_by_pixel+0xb0>
lea    0xe11(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
call   1050 <fprintf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Could not allocate raster line memory.\00"
@.str.1 = [7 x i8] c"\1B*b%dW\00"
define void @index_by_pixel(i32* %0, i64* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i8*
store i32* %0, i32** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %9
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = call i32 @fatal_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
store i32 0, i32* %7
%17 = load i8*, i8** %9
store i8* %17, i8** %10
%18 = load i64*, i64** %5
store i64* %18, i64** %8
br label %19
19: ; preds = %30, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i64*, i64** %8
%25 = getelementptr inbounds i64, i64* %24, i32 1
store i64* %25, i64** %8
%26 = load i64, i64* %24
%27 = trunc i64 %26 to i8
%28 = load i8*, i8** %10
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %10
store i8 %27, i8* %28
br label %30
30: ; preds = %23
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %19
33: ; preds = %19
%34 = load i32*, i32** %4
%35 = load i32, i32* %6
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %9
%38 = load i32, i32* %6
%39 = load i32*, i32** %4
%40 = call i32 @fwrite(i8* %37, i32 1, i32 %38, i32* %39)
%41 = load i8*, i8** %9
%42 = call i32 @free(i8* %41)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"Could not allocate raster line memory.\00"
@.str.1 = [7 x i8] c"\1B*b%dW\00"
define void @index_by_pixel(i32* nocapture %0, i64* nocapture %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @fatal_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %68
10: ; preds = %8
%11 = add i32 %2, -1
%12 = and i32 %2, 7
%13 = icmp ult i32 %11, 7
br i1 %13, label %54, label %14
14: ; preds = %10
%15 = and i32 %2, -8
br label %16
16: ; preds = %16, %14
%17 = phi i8* [ %4, %14 ], [ %51, %16 ]
%18 = phi i64* [ %1, %14 ], [ %48, %16 ]
%19 = phi i32 [ 0, %14 ], [ %52, %16 ]
%20 = getelementptr inbounds i64, i64* %18, i64 1
%21 = load i64, i64* %18
%22 = trunc i64 %21 to i8
%23 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %22, i8* %17
%24 = getelementptr inbounds i64, i64* %18, i64 2
%25 = load i64, i64* %20
%26 = trunc i64 %25 to i8
%27 = getelementptr inbounds i8, i8* %17, i64 2
store i8 %26, i8* %23
%28 = getelementptr inbounds i64, i64* %18, i64 3
%29 = load i64, i64* %24
%30 = trunc i64 %29 to i8
%31 = getelementptr inbounds i8, i8* %17, i64 3
store i8 %30, i8* %27
%32 = getelementptr inbounds i64, i64* %18, i64 4
%33 = load i64, i64* %28
%34 = trunc i64 %33 to i8
%35 = getelementptr inbounds i8, i8* %17, i64 4
store i8 %34, i8* %31
%36 = getelementptr inbounds i64, i64* %18, i64 5
%37 = load i64, i64* %32
%38 = trunc i64 %37 to i8
%39 = getelementptr inbounds i8, i8* %17, i64 5
store i8 %38, i8* %35
%40 = getelementptr inbounds i64, i64* %18, i64 6
%41 = load i64, i64* %36
%42 = trunc i64 %41 to i8
%43 = getelementptr inbounds i8, i8* %17, i64 6
store i8 %42, i8* %39
%44 = getelementptr inbounds i64, i64* %18, i64 7
%45 = load i64, i64* %40
%46 = trunc i64 %45 to i8
%47 = getelementptr inbounds i8, i8* %17, i64 7
store i8 %46, i8* %43
%48 = getelementptr inbounds i64, i64* %18, i64 8
%49 = load i64, i64* %44
%50 = trunc i64 %49 to i8
%51 = getelementptr inbounds i8, i8* %17, i64 8
store i8 %50, i8* %47
%52 = add i32 %19, 8
%53 = icmp eq i32 %52, %15
br i1 %53, label %54, label %16
54: ; preds = %16, %10
%55 = phi i8* [ %4, %10 ], [ %51, %16 ]
%56 = phi i64* [ %1, %10 ], [ %48, %16 ]
%57 = icmp eq i32 %12, 0
br i1 %57, label %68, label %58
58: ; preds = %54, %58
%59 = phi i8* [ %65, %58 ], [ %55, %54 ]
%60 = phi i64* [ %62, %58 ], [ %56, %54 ]
%61 = phi i32 [ %66, %58 ], [ 0, %54 ]
%62 = getelementptr inbounds i64, i64* %60, i64 1
%63 = load i64, i64* %60
%64 = trunc i64 %63 to i8
%65 = getelementptr inbounds i8, i8* %59, i64 1
store i8 %64, i8* %59
%66 = add i32 %61, 1
%67 = icmp eq i32 %66, %12
br i1 %67, label %68, label %58
68: ; preds = %54, %58, %8
%69 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%70 = tail call i32 @fwrite(i8* %4, i32 1, i32 %2, i32* %0)
%71 = tail call i32 @free(i8* %4)
ret void
}