#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 */
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int height;
  int width;
};
typedef TYPE_1__ XImage;

/* Variables and functions */
int XGetPixel(TYPE_1__ *, int, int);
int /*<<< orphan*/ XPutPixel(TYPE_1__ *, int, int, int);
void Extract_Plane(XImage *in_image, XImage *out_image, int plane) {
  register int x, y;
  for (y = 0; y < in_image->height; y++)
    for (x = 0; x < in_image->width; x++)
      XPutPixel(out_image, x, y, (XGetPixel(in_image, x, y) >> plane) & 1);
}


x86 assembly (clang, -O0):
<Extract_Plane>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    11bd <Extract_Plane+0x9d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    0x4(%rcx),%eax
jge    11aa <Extract_Plane+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <XGetPixel@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0x1,%ecx
call   1040 <XPutPixel@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <Extract_Plane+0x30>
jmp    11af <Extract_Plane+0x8f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <Extract_Plane+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Extract_Plane>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%ecx
test   %ecx,%ecx
jle    1184 <Extract_Plane+0x64>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x4(%rdi),%eax
xor    %ebx,%ebx
jmp    1147 <Extract_Plane+0x27>
xchg   %ax,%ax
add    $0x1,%ebx
cmp    %ecx,%ebx
jge    1184 <Extract_Plane+0x64>
test   %eax,%eax
jle    1140 <Extract_Plane+0x20>
xor    %ebp,%ebp
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <XGetPixel@plt>
mov    %r14d,%ecx
shr    %cl,%eax
and    $0x1,%eax
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1040 <XPutPixel@plt>
add    $0x1,%ebp
mov    0x4(%r12),%eax
cmp    %eax,%ebp
jl     1150 <Extract_Plane+0x30>
mov    (%r12),%ecx
jmp    1140 <Extract_Plane+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i32 }
define void @Extract_Plane(%struct.TYPE_6__* %0, %struct.TYPE_6__* %1, i32 %2) {
%4 = alloca %struct.TYPE_6__*
%5 = alloca %struct.TYPE_6__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %4
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %38, %3
%10 = load i32, i32* %8
%11 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %41
15: ; preds = %9
store i32 0, i32* %7
br label %16
16: ; preds = %34, %15
%17 = load i32, i32* %7
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %37
22: ; preds = %16
%23 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = call i32 @XGetPixel(%struct.TYPE_6__* %26, i32 %27, i32 %28)
%30 = load i32, i32* %6
%31 = ashr i32 %29, %30
%32 = and i32 %31, 1
%33 = call i32 @XPutPixel(%struct.TYPE_6__* %23, i32 %24, i32 %25, i32 %32)
br label %34
34: ; preds = %22
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %16
37: ; preds = %16
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %9
41: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i32 }
define void @Extract_Plane(%struct.TYPE_6__* %0, %struct.TYPE_6__* %1, i32 %2) {
%4 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %31
7: ; preds = %3
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 1
%9 = load i32, i32* %8
br label %10
10: ; preds = %7, %26
%11 = phi i32 [ %5, %7 ], [ %27, %26 ]
%12 = phi i32 [ %9, %7 ], [ %28, %26 ]
%13 = phi i32 [ 0, %7 ], [ %29, %26 ]
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %26
15: ; preds = %10, %15
%16 = phi i32 [ %21, %15 ], [ 0, %10 ]
%17 = tail call i32 @XGetPixel(%struct.TYPE_6__* %0, i32 %16, i32 %13)
%18 = lshr i32 %17, %2
%19 = and i32 %18, 1
%20 = tail call i32 @XPutPixel(%struct.TYPE_6__* %1, i32 %16, i32 %13, i32 %19)
%21 = add nuw nsw i32 %16, 1
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %15, label %24
24: ; preds = %15
%25 = load i32, i32* %4
br label %26
26: ; preds = %24, %10
%27 = phi i32 [ %25, %24 ], [ %11, %10 ]
%28 = phi i32 [ %22, %24 ], [ %12, %10 ]
%29 = add nuw nsw i32 %13, 1
%30 = icmp slt i32 %29, %27
br i1 %30, label %10, label %31
31: ; preds = %26, %3
ret void
}