#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*/ putchar(int);
void packpixel(char *data, int c) {
  int i = 0, n = 0;
  while (c--) {
    i = (i << 3) | (*data++ & 0x7);
    if ((n += 3) >= 8)
      putchar((i >> (n -= 8)) & 0xFF);
  }
  if (n)
    putchar(i << (8 - n));
  return;
}


x86 assembly (clang, -O0):
<packpixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1191 <packpixel+0x81>
mov    -0x10(%rbp),%eax
shl    $0x3,%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
and    $0x7,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x8,%eax
jl     118c <packpixel+0x7c>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%ecx
sub    $0x8,%ecx
mov    %ecx,-0x14(%rbp)
sar    %cl,%edi
and    $0xff,%edi
call   1030 <putchar@plt>
jmp    112d <packpixel+0x1d>
cmpl   $0x0,-0x14(%rbp)
je     11ad <packpixel+0x9d>
mov    -0x10(%rbp),%edi
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
shl    %cl,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packpixel>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     117d <packpixel+0x6d>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    114b <packpixel+0x3b>
nopl   0x0(%rax,%rax,1)
add    $0xfffffffb,%ebp
mov    %r12d,%eax
mov    %ebp,%ecx
sar    %cl,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
je     1161 <packpixel+0x51>
movzbl (%r14,%rbx,1),%eax
and    $0x7,%eax
lea    (%rax,%r12,8),%r12d
cmp    $0x5,%ebp
jge    1130 <packpixel+0x20>
add    $0x3,%ebp
jmp    1142 <packpixel+0x32>
test   %ebp,%ebp
je     117d <packpixel+0x6d>
mov    $0x8,%cl
sub    %bpl,%cl
shl    %cl,%r12d
mov    %r12d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @packpixel(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* %5
store i32 0, i32* %6
br label %7
7: ; preds = %30, %2
%8 = load i32, i32* %4
%9 = add nsw i32 %8, -1
store i32 %9, i32* %4
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i32, i32* %5
%13 = shl i32 %12, 3
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = and i32 %17, 7
%19 = or i32 %13, %18
store i32 %19, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 3
store i32 %21, i32* %6
%22 = icmp sge i32 %21, 8
br i1 %22, label %23, label %30
23: ; preds = %11
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 8
store i32 %26, i32* %6
%27 = ashr i32 %24, %26
%28 = and i32 %27, 255
%29 = call i32 @putchar(i32 %28)
br label %30
30: ; preds = %23, %11
br label %7
31: ; preds = %7
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = sub nsw i32 8, %36
%38 = shl i32 %35, %37
%39 = call i32 @putchar(i32 %38)
br label %40
40: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
define void @packpixel(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %32, label %4
4: ; preds = %2, %23
%5 = phi i32 [ %9, %23 ], [ %1, %2 ]
%6 = phi i32 [ %24, %23 ], [ 0, %2 ]
%7 = phi i32 [ %15, %23 ], [ 0, %2 ]
%8 = phi i8* [ %11, %23 ], [ %0, %2 ]
%9 = add nsw i32 %5, -1
%10 = shl i32 %7, 3
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = load i8, i8* %8
%13 = and i8 %12, 7
%14 = zext i8 %13 to i32
%15 = or i32 %10, %14
%16 = add nsw i32 %6, 3
%17 = icmp sgt i32 %6, 4
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = add nsw i32 %6, -5
%20 = ashr i32 %15, %19
%21 = and i32 %20, 255
%22 = tail call i32 @putchar(i32 %21)
br label %23
23: ; preds = %18, %4
%24 = phi i32 [ %19, %18 ], [ %16, %4 ]
%25 = icmp eq i32 %9, 0
br i1 %25, label %26, label %4
26: ; preds = %23
%27 = icmp eq i32 %24, 0
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = sub nsw i32 8, %24
%30 = shl i32 %15, %29
%31 = tail call i32 @putchar(i32 %30)
br label %32
32: ; preds = %2, %28, %26
ret void
}