#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*/ draw_pixel(int, int, char, char, char, int);
void draw_fillrect(int x1, int y1, int x2, int y2, char r, char g, char b,
                   int screen) {
  int X1, X2, Y1, Y2, i, j;
  if (x1 < x2) {
    X1 = x1;
    X2 = x2;
  } else {
    X1 = x2;
    X2 = x1;
  }
  if (y1 < y2) {
    Y1 = y1;
    Y2 = y2;
  } else {
    Y1 = y2;
    Y2 = y1;
  }
  for (i = X1; i <= X2; i++) {
    for (j = Y1; j <= Y2; j++) {
      draw_pixel(i, j, r, g, b, screen);
    }
  }
}


x86 assembly (clang, -O0):
<draw_fillrect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x3c(%rbp)
mov    %ecx,%eax
mov    -0x3c(%rbp),%ecx
mov    %eax,-0x38(%rbp)
mov    %edx,%eax
mov    -0x38(%rbp),%edx
mov    %eax,-0x34(%rbp)
mov    %esi,%eax
mov    -0x34(%rbp),%esi
mov    %eax,-0x30(%rbp)
mov    %edi,%r8d
mov    -0x30(%rbp),%edi
mov    %r9b,%al
mov    0x18(%rbp),%r9d
mov    0x10(%rbp),%r9b
mov    %r8d,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1175 <draw_fillrect+0x65>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <draw_fillrect+0x71>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119e <draw_fillrect+0x8e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <draw_fillrect+0x9a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1211 <draw_fillrect+0x101>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     11fe <draw_fillrect+0xee>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x11(%rbp),%dl
mov    -0x12(%rbp),%cl
mov    0x10(%rbp),%al
mov    0x18(%rbp),%r9d
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %al,%r8d
call   1030 <draw_pixel@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c2 <draw_fillrect+0xb2>
jmp    1203 <draw_fillrect+0xf3>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b0 <draw_fillrect+0xa0>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_fillrect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    %edx,%edi
mov    %edx,%ebx
cmovl  %edi,%ebx
mov    0x58(%rsp),%r12d
cmovl  %edx,%edi
mov    %edi,0x10(%rsp)
cmp    %ecx,%esi
mov    %ecx,%edx
cmovl  %esi,%edx
mov    %edx,0xc(%rsp)
cmovl  %ecx,%esi
add    $0x1,%esi
movsbl %r8b,%ebp
movsbl %r9b,%r14d
movsbl 0x50(%rsp),%r13d
mov    %esi,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %r13d,%r8d
mov    %r12d,%r9d
call   1030 <draw_pixel@plt>
mov    0x14(%rsp),%esi
add    $0x1,%r15d
cmp    %r15d,%esi
jne    1170 <draw_fillrect+0x60>
lea    0x1(%rbx),%edx
cmp    0x10(%rsp),%ebx
mov    %edx,%ebx
jne    1160 <draw_fillrect+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @draw_fillrect(i32 %0, i32 %1, i32 %2, i32 %3, i8 signext %4, i8 signext %5, i8 signext %6, i32 %7) {
%9 = icmp slt i32 %0, %2
%10 = select i1 %9, i32 %0, i32 %2
%11 = select i1 %9, i32 %2, i32 %0
%12 = icmp slt i32 %1, %3
%13 = select i1 %12, i32 %1, i32 %3
%14 = select i1 %12, i32 %3, i32 %1
br label %15
15: ; preds = %8, %22
%16 = phi i32 [ %10, %8 ], [ %23, %22 ]
br label %17
17: ; preds = %15, %17
%18 = phi i32 [ %13, %15 ], [ %20, %17 ]
%19 = tail call i32 @draw_pixel(i32 %16, i32 %18, i8 signext %4, i8 signext %5, i8 signext %6, i32 %7)
%20 = add i32 %18, 1
%21 = icmp eq i32 %18, %14
br i1 %21, label %22, label %17
22: ; preds = %17
%23 = add i32 %16, 1
%24 = icmp eq i32 %16, %11
br i1 %24, label %25, label %15
25: ; preds = %22
ret void
}