#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int width;
  int height;
};
typedef TYPE_1__ XRectangle;
typedef int /*<<< orphan*/ Pixmap;
typedef int /*<<< orphan*/ GC;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XDrawLine(int /*<<< orphan*/ *, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/, int, int,
                             int);
int /*<<< orphan*/ XSetForeground(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  unsigned long);
void draw_background(Display *d, Pixmap pix, GC gc, XRectangle r,
                     unsigned long *pal) {
  int i, x, y;
  x = r.width - 1;
  for (i = 0; i < r.height; i++) {
    y = r.height - i - 1;
    XSetForeground(d, gc, pal[i]);
    XDrawLine(d, pix, gc, 0, y, x, y);
  }
}


x86 assembly (clang, -O0):
<draw_background>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rcx,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a7 <draw_background+0x87>
mov    -0x4(%rbp),%eax
sub    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1030 <XSetForeground@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x2c(%rbp),%eax
xor    %ecx,%ecx
mov    %eax,(%rsp)
call   1040 <XDrawLine@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <draw_background+0x2a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_background>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %esi,0x14(%rsp)
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
shr    $0x20,%r12
test   %r12d,%r12d
jle    11a7 <draw_background+0x87>
mov    %r8,%r14
mov    %edx,%r13d
mov    %rdi,%rbx
mov    0x8(%rsp),%rax
add    $0xffffffff,%eax
mov    %rax,0x8(%rsp)
lea    -0x1(%r12),%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%r15,8),%rdx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <XSetForeground@plt>
mov    %ebp,(%rsp)
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
mov    %r13d,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
mov    0x8(%rsp),%r9
call   1040 <XDrawLine@plt>
add    $0x1,%r15
add    $0xffffffff,%ebp
cmp    %r15,%r12
jne    1170 <draw_background+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define void @draw_background(i32* %0, i32 %1, i32 %2, i64 %3, i64* %4) {
%6 = alloca %struct.TYPE_3__
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = bitcast %struct.TYPE_3__* %6 to i64*
store i64 %3, i64* %14
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i64* %4, i64** %10
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %12
store i32 0, i32* %11
br label %18
18: ; preds = %44, %5
%19 = load i32, i32* %11
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %47
23: ; preds = %18
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load i32, i32* %11
%27 = sub nsw i32 %25, %26
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %13
%29 = load i32*, i32** %7
%30 = load i32, i32* %9
%31 = load i64*, i64** %10
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i64, i64* %31, i64 %33
%35 = load i64, i64* %34
%36 = call i32 @XSetForeground(i32* %29, i32 %30, i64 %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = load i32, i32* %13
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = call i32 @XDrawLine(i32* %37, i32 %38, i32 %39, i32 0, i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %23
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %18
47: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @draw_background(i32* %0, i32 %1, i32 %2, i64 %3, i64* nocapture %4) {
%6 = trunc i64 %3 to i32
%7 = lshr i64 %3, 32
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %6, -1
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %22
11: ; preds = %5, %11
%12 = phi i64 [ %20, %11 ], [ 0, %5 ]
%13 = trunc i64 %12 to i32
%14 = xor i32 %13, -1
%15 = add i32 %14, %8
%16 = getelementptr inbounds i64, i64* %4, i64 %12
%17 = load i64, i64* %16
%18 = tail call i32 @XSetForeground(i32* %0, i32 %2, i64 %17)
%19 = tail call i32 @XDrawLine(i32* %0, i32 %1, i32 %2, i32 0, i32 %15, i32 %9, i32 %15)
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %7
br i1 %21, label %22, label %11
22: ; preds = %11, %5
ret void
}