#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*/ tga_set_pixel(unsigned int, unsigned int, int, int, int);
void tga_draw_hline(unsigned x, unsigned y, unsigned cnt,
                    unsigned is_foreground) {
  while (cnt > 0) {
    cnt--;
    if (is_foreground == 0)
      tga_set_pixel(x + cnt, y, 0x0e8, 0x0e8, 0x0e8);
    else
      tga_set_pixel(x + cnt, y, 255, 0, 0);
  }
}


x86 assembly (clang, -O0):
<tga_draw_hline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    117e <tga_draw_hline+0x6e>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1160 <tga_draw_hline+0x50>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xe8,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <tga_set_pixel@plt>
jmp    1179 <tga_draw_hline+0x69>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xff,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <tga_set_pixel@plt>
jmp    1124 <tga_draw_hline+0x14>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tga_draw_hline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     1163 <tga_draw_hline+0x53>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%ebp
add    $0xffffffff,%ebp
jmp    1143 <tga_draw_hline+0x33>
nopw   0x0(%rax,%rax,1)
mov    $0xff,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <tga_set_pixel@plt>
test   %ebx,%ebx
je     1163 <tga_draw_hline+0x53>
lea    (%rbx,%rbp,1),%edi
add    $0xffffffff,%ebx
mov    %r15d,%esi
test   %r14d,%r14d
jne    1130 <tga_draw_hline+0x20>
mov    $0xe8,%edx
mov    $0xe8,%ecx
mov    $0xe8,%r8d
jmp    113a <tga_draw_hline+0x2a>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @tga_draw_hline(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %9
9: ; preds = %29, %4
%10 = load i32, i32* %7
%11 = icmp ugt i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i32, i32* %7
%14 = add i32 %13, -1
store i32 %14, i32* %7
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = add i32 %18, %19
%21 = load i32, i32* %6
%22 = call i32 @tga_set_pixel(i32 %20, i32 %21, i32 232, i32 232, i32 232)
br label %29
23: ; preds = %12
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = add i32 %24, %25
%27 = load i32, i32* %6
%28 = call i32 @tga_set_pixel(i32 %26, i32 %27, i32 255, i32 0, i32 0)
br label %29
29: ; preds = %23, %17
br label %9
30: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @tga_draw_hline(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %18, label %6
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br label %8
8: ; preds = %6, %16
%9 = phi i32 [ %2, %6 ], [ %10, %16 ]
%10 = add i32 %9, -1
%11 = add i32 %10, %0
br i1 %7, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @tga_set_pixel(i32 %11, i32 %1, i32 232, i32 232, i32 232)
br label %16
14: ; preds = %8
%15 = tail call i32 @tga_set_pixel(i32 %11, i32 %1, i32 255, i32 0, i32 0)
br label %16
16: ; preds = %14, %12
%17 = icmp eq i32 %10, 0
br i1 %17, label %18, label %8
18: ; preds = %16, %4
ret void
}