#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 */
unsigned char *decode_byte(unsigned char *, unsigned char *, int);
unsigned int up8(int);
unsigned char *decode_line(unsigned char *dest, unsigned char *src, int w) {
  unsigned int w8;
  unsigned int bpp;
  unsigned char b[4];
  int i;
  unsigned char *p;
  p = src;
  w8 = up8(w);
  bpp = w8 >> 3;
  while (w > 0) {
    for (i = 0; i < 4; ++i)
      b[i] = p[i * bpp];
    if (w > 8)
      dest = decode_byte(dest, b, 8);
    else
      dest = decode_byte(dest, b, w);
    w -= 8;
    ++p;
  }
  return (src + bpp * 4);
}


x86 assembly (clang, -O0):
<decode_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <up8@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x3,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e3 <decode_line+0xc3>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1190 <decode_line+0x70>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <decode_line+0x40>
cmpl   $0x8,-0x14(%rbp)
jle    11b5 <decode_line+0x95>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <decode_byte@plt>
mov    %rax,-0x8(%rbp)
jmp    11c9 <decode_line+0xa9>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <decode_byte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    114f <decode_line+0x2f>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%edi
call   1030 <up8@plt>
mov    %eax,%r12d
shr    $0x3,%r12
test   %ebp,%ebp
jle    11e6 <decode_line+0xc6>
lea    (%r12,%r12,2),%r13
mov    (%r14),%al
mov    %al,0xc(%rsp)
mov    (%r14,%r12,1),%al
mov    %al,0xd(%rsp)
mov    (%r14,%r12,2),%al
mov    %al,0xe(%rsp)
mov    (%r14,%r13,1),%al
mov    %al,0xf(%rsp)
cmp    $0x9,%ebp
mov    %r14,0x10(%rsp)
jb     11d2 <decode_line+0xb2>
add    $0x1,%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <decode_byte@plt>
mov    %rax,%rbx
add    $0xfffffff8,%ebp
movzbl (%r14),%eax
mov    %al,0xc(%rsp)
movzbl (%r14,%r12,1),%eax
mov    %al,0xd(%rsp)
movzbl (%r14,%r12,2),%eax
mov    %al,0xe(%rsp)
movzbl (%r14,%r13,1),%eax
mov    %al,0xf(%rsp)
add    $0x1,%r14
cmp    $0x8,%ebp
ja     1190 <decode_line+0x70>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <decode_byte@plt>
mov    0x10(%rsp),%r14
mov    %r12d,%eax
lea    (%r14,%rax,4),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @decode_line(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8]
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
store i8* %12, i8** %11
%13 = load i32, i32* %6
%14 = call i32 @up8(i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = lshr i32 %15, 3
store i32 %16, i32* %8
br label %17
17: ; preds = %50, %3
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %17
store i32 0, i32* %10
br label %21
21: ; preds = %35, %20
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i8*, i8** %11
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = mul i32 %26, %27
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %24
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %21
38: ; preds = %21
%39 = load i32, i32* %6
%40 = icmp sgt i32 %39, 8
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%44 = call i8* @decode_byte(i8* %42, i8* %43, i32 8)
store i8* %44, i8** %4
br label %50
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* %6
%49 = call i8* @decode_byte(i8* %46, i8* %47, i32 %48)
store i8* %49, i8** %4
br label %50
50: ; preds = %45, %41
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 8
store i32 %52, i32* %6
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %11
br label %17
55: ; preds = %17
%56 = load i8*, i8** %5
%57 = load i32, i32* %8
%58 = mul i32 %57, 4
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
ret i8* %60
}

LLVM IR (-O2):
define i8* @decode_line(i8* %0, i8* %1, i32 %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @up8(i32 %2)
%7 = lshr i32 %6, 3
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %43
9: ; preds = %3
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%12 = shl nuw nsw i64 %10, 1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%14 = mul nuw nsw i64 %10, 3
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%16 = load i8, i8* %1
store i8 %16, i8* %5
%17 = getelementptr inbounds i8, i8* %1, i64 %10
%18 = load i8, i8* %17
store i8 %18, i8* %11
%19 = getelementptr inbounds i8, i8* %1, i64 %12
%20 = load i8, i8* %19
store i8 %20, i8* %13
%21 = getelementptr inbounds i8, i8* %1, i64 %14
%22 = load i8, i8* %21
store i8 %22, i8* %15
%23 = icmp ugt i32 %2, 8
br i1 %23, label %24, label %39
24: ; preds = %9, %24
%25 = phi i32 [ %29, %24 ], [ %2, %9 ]
%26 = phi i8* [ %28, %24 ], [ %0, %9 ]
%27 = phi i8* [ %30, %24 ], [ %1, %9 ]
%28 = call i8* @decode_byte(i8* %26, i8* %5, i32 8)
%29 = add nsw i32 %25, -8
%30 = getelementptr inbounds i8, i8* %27, i64 1
%31 = load i8, i8* %30
store i8 %31, i8* %5
%32 = getelementptr inbounds i8, i8* %30, i64 %10
%33 = load i8, i8* %32
store i8 %33, i8* %11
%34 = getelementptr inbounds i8, i8* %30, i64 %12
%35 = load i8, i8* %34
store i8 %35, i8* %13
%36 = getelementptr inbounds i8, i8* %30, i64 %14
%37 = load i8, i8* %36
store i8 %37, i8* %15
%38 = icmp ugt i32 %29, 8
br i1 %38, label %24, label %39
39: ; preds = %24, %9
%40 = phi i8* [ %0, %9 ], [ %28, %24 ]
%41 = phi i32 [ %2, %9 ], [ %29, %24 ]
%42 = call i8* @decode_byte(i8* %40, i8* %5, i32 %41)
br label %43
43: ; preds = %39, %3
%44 = shl nuw nsw i32 %7, 2
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %1, i64 %45
ret i8* %46
}