#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*/ subpixels(int /*<<< orphan*/, unsigned long *,
                             unsigned long *, unsigned long *, unsigned long *);
void buffer_join(unsigned long *restrict restrict *layer,
                 unsigned long *restrict *restrict base, unsigned long width,
                 unsigned long height, unsigned long offx, unsigned long offy) {
  unsigned long x, y, a, r, g, b;
  unsigned long *restrict layer_column;
  unsigned long *restrict base_column;
  base += offx;
  for (x = 0; x < width; x++) {
    layer_column = *layer++;
    base_column = *base++ + offy;
    for (y = 0; y < height; y++, base_column++) {
      subpixels(*layer_column++, &a, &r, &g, &b);
      if (a == 255)
        *base_column = (r << 16) | (g << 8) | b;
    }
  }
}


x86 assembly (clang, -O0):
<buffer_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1230 <buffer_join+0x120>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    121a <buffer_join+0x10a>
mov    -0x68(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x68(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
lea    -0x60(%rbp),%r8
call   1030 <subpixels@plt>
cmpq   $0xff,-0x48(%rbp)
jne    11f8 <buffer_join+0xe8>
mov    -0x50(%rbp),%rcx
shl    $0x10,%rcx
mov    -0x58(%rbp),%rax
shl    $0x8,%rax
or     %rax,%rcx
or     -0x60(%rbp),%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,(%rax)
jmp    11fd <buffer_join+0xed>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x70(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x70(%rbp)
jmp    1195 <buffer_join+0x85>
jmp    121f <buffer_join+0x10f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1148 <buffer_join+0x38>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,(%rsp)
mov    %rdi,0x10(%rsp)
mov    %rdx,0x18(%rsp)
test   %rdx,%rdx
je     11ee <buffer_join+0xde>
mov    %rcx,%rbx
lea    (%rsi,%r8,8),%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
shlq   $0x3,(%rsp)
lea    0x30(%rsp),%r14
lea    0x28(%rsp),%r15
jmp    117c <buffer_join+0x6c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addq   $0x8,0x10(%rsp)
addq   $0x8,0x8(%rsp)
mov    0x20(%rsp),%rax
add    $0x1,%rax
cmp    0x18(%rsp),%rax
je     11ee <buffer_join+0xde>
mov    %rax,0x20(%rsp)
test   %rbx,%rbx
je     1160 <buffer_join+0x50>
mov    0x8(%rsp),%rax
mov    (%rax),%r12
add    (%rsp),%r12
mov    0x10(%rsp),%rax
mov    (%rax),%r13
xor    %ebp,%ebp
jmp    11a9 <buffer_join+0x99>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1160 <buffer_join+0x50>
mov    0x0(%r13,%rbp,8),%edi
lea    0x40(%rsp),%rsi
lea    0x38(%rsp),%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1030 <subpixels@plt>
cmpq   $0xff,0x40(%rsp)
jne    11a0 <buffer_join+0x90>
mov    0x38(%rsp),%rax
shl    $0x10,%rax
mov    0x30(%rsp),%rcx
shl    $0x8,%rcx
or     %rax,%rcx
or     0x28(%rsp),%rcx
mov    %rcx,(%r12,%rbp,8)
jmp    11a0 <buffer_join+0x90>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @buffer_join(i64** %0, i64** noalias %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = alloca i64**
%8 = alloca i64**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64*
%20 = alloca i64*
store i64** %0, i64*** %7
store i64** %1, i64*** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i64 %5, i64* %12
%21 = load i64, i64* %11
%22 = load i64**, i64*** %8
%23 = getelementptr inbounds i64*, i64** %22, i64 %21
store i64** %23, i64*** %8
store i64 0, i64* %13
br label %24
24: ; preds = %65, %6
%25 = load i64, i64* %13
%26 = load i64, i64* %9
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %68
28: ; preds = %24
%29 = load i64**, i64*** %7
%30 = getelementptr inbounds i64*, i64** %29, i32 1
store i64** %30, i64*** %7
%31 = load i64*, i64** %29
store i64* %31, i64** %19
%32 = load i64**, i64*** %8
%33 = getelementptr inbounds i64*, i64** %32, i32 1
store i64** %33, i64*** %8
%34 = load i64*, i64** %32
%35 = load i64, i64* %12
%36 = getelementptr inbounds i64, i64* %34, i64 %35
store i64* %36, i64** %20
store i64 0, i64* %14
br label %37
37: ; preds = %59, %28
%38 = load i64, i64* %14
%39 = load i64, i64* %10
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %64
41: ; preds = %37
%42 = load i64*, i64** %19
%43 = getelementptr inbounds i64, i64* %42, i32 1
store i64* %43, i64** %19
%44 = load i64, i64* %42
%45 = trunc i64 %44 to i32
%46 = call i32 @subpixels(i32 %45, i64* %15, i64* %16, i64* %17, i64* %18)
%47 = load i64, i64* %15
%48 = icmp eq i64 %47, 255
br i1 %48, label %49, label %58
49: ; preds = %41
%50 = load i64, i64* %16
%51 = shl i64 %50, 16
%52 = load i64, i64* %17
%53 = shl i64 %52, 8
%54 = or i64 %51, %53
%55 = load i64, i64* %18
%56 = or i64 %54, %55
%57 = load i64*, i64** %20
store i64 %56, i64* %57
br label %58
58: ; preds = %49, %41
br label %59
59: ; preds = %58
%60 = load i64, i64* %14
%61 = add i64 %60, 1
store i64 %61, i64* %14
%62 = load i64*, i64** %20
%63 = getelementptr inbounds i64, i64* %62, i32 1
store i64* %63, i64** %20
br label %37
64: ; preds = %37
br label %65
65: ; preds = %64
%66 = load i64, i64* %13
%67 = add i64 %66, 1
store i64 %67, i64* %13
br label %24
68: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @buffer_join(i64** nocapture %0, i64** noalias nocapture %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = bitcast i64* %7 to i8*
%12 = bitcast i64* %8 to i8*
%13 = bitcast i64* %9 to i8*
%14 = bitcast i64* %10 to i8*
%15 = icmp eq i64 %2, 0
br i1 %15, label %54, label %16
16: ; preds = %6
%17 = getelementptr inbounds i64*, i64** %1, i64 %4
%18 = icmp eq i64 %3, 0
br label %19
19: ; preds = %16, %51
%20 = phi i64 [ 0, %16 ], [ %52, %51 ]
%21 = phi i64** [ %0, %16 ], [ %23, %51 ]
%22 = phi i64** [ %17, %16 ], [ %24, %51 ]
%23 = getelementptr inbounds i64*, i64** %21, i64 1
%24 = getelementptr inbounds i64*, i64** %22, i64 1
br i1 %18, label %51, label %25
25: ; preds = %19
%26 = load i64*, i64** %22
%27 = getelementptr inbounds i64, i64* %26, i64 %5
%28 = load i64*, i64** %21
br label %29
29: ; preds = %25, %47
%30 = phi i64* [ %49, %47 ], [ %27, %25 ]
%31 = phi i64* [ %33, %47 ], [ %28, %25 ]
%32 = phi i64 [ %48, %47 ], [ 0, %25 ]
%33 = getelementptr inbounds i64, i64* %31, i64 1
%34 = load i64, i64* %31
%35 = trunc i64 %34 to i32
%36 = call i32 @subpixels(i32 %35, i64* %7, i64* %8, i64* %9, i64* %10)
%37 = load i64, i64* %7
%38 = icmp eq i64 %37, 255
br i1 %38, label %39, label %47
39: ; preds = %29
%40 = load i64, i64* %8
%41 = shl i64 %40, 16
%42 = load i64, i64* %9
%43 = shl i64 %42, 8
%44 = or i64 %43, %41
%45 = load i64, i64* %10
%46 = or i64 %44, %45
store i64 %46, i64* %30
br label %47
47: ; preds = %29, %39
%48 = add nuw i64 %32, 1
%49 = getelementptr inbounds i64, i64* %30, i64 1
%50 = icmp eq i64 %48, %3
br i1 %50, label %51, label %29
51: ; preds = %47, %19
%52 = add nuw i64 %20, 1
%53 = icmp eq i64 %52, %2
br i1 %53, label %54, label %19
54: ; preds = %51, %6
ret void
}