#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*/ write_pixel(int, int, short);
void drawBox(int x, int y, int sidelength, short colour) {
  int i;
  for (i = 0; i <= sidelength; i++) {
    write_pixel(x, y + i, colour);
    write_pixel(x + i, y, colour);
    write_pixel(x + sidelength, y + i, colour);
    write_pixel(x + i, y + sidelength, colour);
  }
}


x86 assembly (clang, -O0):
<drawBox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1197 <drawBox+0x87>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x14(%rbp),%esi
movswl -0xe(%rbp),%edx
call   1030 <write_pixel@plt>
mov    -0x4(%rbp),%edi
add    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
movswl -0xe(%rbp),%edx
call   1030 <write_pixel@plt>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x14(%rbp),%esi
movswl -0xe(%rbp),%edx
call   1030 <write_pixel@plt>
mov    -0x4(%rbp),%edi
add    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0xc(%rbp),%esi
movswl -0xe(%rbp),%edx
call   1030 <write_pixel@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <drawBox+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawBox>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
js     1198 <drawBox+0x88>
mov    %esi,%r15d
mov    %edi,%ebx
mov    %rdx,%rax
add    %ebx,%edx
mov    %edx,0xc(%rsp)
lea    (%rax,%r15,1),%edx
mov    %edx,0x8(%rsp)
add    $0x1,%eax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
movswl %cx,%ebp
cs nopw 0x0(%rax,%rax,1)
lea    (%r15,%r13,1),%r12d
mov    %ebx,%edi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <write_pixel@plt>
lea    (%rbx,%r13,1),%r14d
mov    %r14d,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <write_pixel@plt>
mov    0xc(%rsp),%edi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <write_pixel@plt>
mov    %r14d,%edi
mov    0x8(%rsp),%esi
mov    %ebp,%edx
call   1030 <write_pixel@plt>
add    $0x1,%r13d
cmp    %r13d,0x10(%rsp)
jne    1150 <drawBox+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @drawBox(i32 %0, i32 %1, i32 %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i16 %3, i16* %8
store i32 0, i32* %9
br label %10
10: ; preds = %43, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = load i32, i32* %9
%18 = add nsw i32 %16, %17
%19 = load i16, i16* %8
%20 = call i32 @write_pixel(i32 %15, i32 %18, i16 signext %19)
%21 = load i32, i32* %5
%22 = load i32, i32* %9
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %6
%25 = load i16, i16* %8
%26 = call i32 @write_pixel(i32 %23, i32 %24, i16 signext %25)
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %9
%32 = add nsw i32 %30, %31
%33 = load i16, i16* %8
%34 = call i32 @write_pixel(i32 %29, i32 %32, i16 signext %33)
%35 = load i32, i32* %5
%36 = load i32, i32* %9
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %38, %39
%41 = load i16, i16* %8
%42 = call i32 @write_pixel(i32 %37, i32 %40, i16 signext %41)
br label %43
43: ; preds = %14
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %10
46: ; preds = %10
ret void
}

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