#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 get_screen_columns();
int get_screen_rows();
int /*<<< orphan*/ gotoxy(int, int);
int /*<<< orphan*/ lineh(int, int, int, char);
int /*<<< orphan*/ linev(int, int, int, char);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ sprintf(char *, char *);
void box(int x, int y, int length, int height, int type) {
  char charset[10];
  if ((x < 0) || (y < 0) || (length < 0) || (height < 0) ||
      ((x + length) > get_screen_columns()) ||
      ((y + height) > get_screen_rows()))
    return;
  else {
    switch (type) {
    case 1:
      sprintf(charset, "++++-|");
      break;
    case 2:
      sprintf(charset, "++++=|");
      break;
    default:
      sprintf(charset, "++++-|");
      break;
    }
    lineh(x, y, length, charset[4]);
    lineh(x, y + height - 1, length, charset[4]);
    linev(x, y, height, charset[5]);
    linev(x + length - 1, y, height, charset[5]);
    gotoxy(x, y);
    putchar(charset[0]);
    gotoxy(x, y + height - 1);
    putchar(charset[1]);
    gotoxy(x + length - 1, y);
    putchar(charset[2]);
    gotoxy(x + length - 1, y + height - 1);
    putchar(charset[3]);
    gotoxy(0, y + height + 2);
  }
}


x86 assembly (clang, -O0):
<box>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     11ea <box+0x7a>
cmpl   $0x0,-0x8(%rbp)
jl     11ea <box+0x7a>
cmpl   $0x0,-0xc(%rbp)
jl     11ea <box+0x7a>
cmpl   $0x0,-0x10(%rbp)
jl     11ea <box+0x7a>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1090 <get_screen_columns@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jg     11ea <box+0x7a>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <get_screen_rows@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    11ef <box+0x7f>
jmp    131a <box+0x1aa>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     1214 <box+0xa4>
jmp    1203 <box+0x93>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     1229 <box+0xb9>
jmp    123e <box+0xce>
lea    -0x1e(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1080 <sprintf@plt>
jmp    124e <box+0xde>
lea    -0x1e(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1080 <sprintf@plt>
jmp    124e <box+0xde>
lea    -0x1e(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
movsbl -0x1a(%rbp),%ecx
call   1050 <lineh@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0xc(%rbp),%edx
movsbl -0x1a(%rbp),%ecx
call   1050 <lineh@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
movsbl -0x19(%rbp),%ecx
call   1070 <linev@plt>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
movsbl -0x19(%rbp),%ecx
call   1070 <linev@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <gotoxy@plt>
movsbl -0x1e(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x10(%rbp),%esi
sub    $0x1,%esi
call   1060 <gotoxy@plt>
movsbl -0x1d(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
call   1060 <gotoxy@plt>
movsbl -0x1c(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
add    -0x10(%rbp),%esi
sub    $0x1,%esi
call   1060 <gotoxy@plt>
movsbl -0x1b(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%esi
add    -0x10(%rbp),%esi
add    $0x2,%esi
xor    %edi,%edi
call   1060 <gotoxy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<box>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%eax
or     %edi,%eax
or     %edx,%eax
or     %ecx,%eax
js     11b3 <box+0x53>
mov    %r8d,%r14d
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%ebp
lea    (%rbx,%rbp,1),%r15d
xor    %eax,%eax
call   1080 <get_screen_columns@plt>
cmp    %eax,%r15d
jg     11b3 <box+0x53>
mov    %r14d,0x8(%rsp)
lea    (%r12,%r13,1),%r14d
xor    %eax,%eax
call   1040 <get_screen_rows@plt>
mov    %r14,0x10(%rsp)
cmp    %eax,%r14d
mov    0x8(%rsp),%eax
jle    11c2 <box+0x62>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,0xc(%rsp)
xor    %r15d,%r15d
cmp    $0x2,%eax
sete   %r15b
shl    $0x4,%r15d
or     $0x2d,%r15d
mov    %ebp,%edi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1050 <lineh@plt>
mov    0x10(%rsp),%r14
lea    -0x1(%r14),%esi
mov    %esi,0x8(%rsp)
mov    %ebp,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1050 <lineh@plt>
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    $0x7c,%ecx
call   1070 <linev@plt>
mov    0xc(%rsp),%ebx
add    $0xffffffff,%ebx
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    $0x7c,%ecx
call   1070 <linev@plt>
mov    %ebp,%edi
mov    %r12d,%esi
call   1060 <gotoxy@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    0x8(%rsp),%ebp
mov    %ebp,%esi
call   1060 <gotoxy@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
mov    %r12d,%esi
call   1060 <gotoxy@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <gotoxy@plt>
mov    $0x2b,%edi
call   1030 <putchar@plt>
add    $0x2,%r14d
xor    %edi,%edi
mov    %r14d,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <gotoxy@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"++++-|\00"
@.str.1 = [7 x i8] c"++++=|\00"
define void @box(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %35, label %14
14: ; preds = %5
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %14
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %17
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = load i32, i32* %6
%25 = load i32, i32* %8
%26 = add nsw i32 %24, %25
%27 = call i32 (...) @get_screen_columns()
%28 = icmp sgt i32 %26, %27
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = load i32, i32* %7
%31 = load i32, i32* %9
%32 = add nsw i32 %30, %31
%33 = call i32 (...) @get_screen_rows()
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %29, %23, %20, %17, %14, %5
br label %119
36: ; preds = %29
%37 = load i32, i32* %10
switch i32 %37, label %44 [
i32 1, label %38
i32 2, label %41
]
38: ; preds = %36
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%40 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %47
41: ; preds = %36
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%43 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %47
44: ; preds = %36
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%46 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %44, %41, %38
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 4
%52 = load i8, i8* %51
%53 = call i32 @lineh(i32 %48, i32 %49, i32 %50, i8 signext %52)
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = load i32, i32* %9
%57 = add nsw i32 %55, %56
%58 = sub nsw i32 %57, 1
%59 = load i32, i32* %8
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 4
%61 = load i8, i8* %60
%62 = call i32 @lineh(i32 %54, i32 %58, i32 %59, i8 signext %61)
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %9
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 5
%67 = load i8, i8* %66
%68 = call i32 @linev(i32 %63, i32 %64, i32 %65, i8 signext %67)
%69 = load i32, i32* %6
%70 = load i32, i32* %8
%71 = add nsw i32 %69, %70
%72 = sub nsw i32 %71, 1
%73 = load i32, i32* %7
%74 = load i32, i32* %9
%75 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 5
%76 = load i8, i8* %75
%77 = call i32 @linev(i32 %72, i32 %73, i32 %74, i8 signext %76)
%78 = load i32, i32* %6
%79 = load i32, i32* %7
%80 = call i32 @gotoxy(i32 %78, i32 %79)
%81 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%82 = load i8, i8* %81
%83 = call i32 @putchar(i8 signext %82)
%84 = load i32, i32* %6
%85 = load i32, i32* %7
%86 = load i32, i32* %9
%87 = add nsw i32 %85, %86
%88 = sub nsw i32 %87, 1
%89 = call i32 @gotoxy(i32 %84, i32 %88)
%90 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 1
%91 = load i8, i8* %90
%92 = call i32 @putchar(i8 signext %91)
%93 = load i32, i32* %6
%94 = load i32, i32* %8
%95 = add nsw i32 %93, %94
%96 = sub nsw i32 %95, 1
%97 = load i32, i32* %7
%98 = call i32 @gotoxy(i32 %96, i32 %97)
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 2
%100 = load i8, i8* %99
%101 = call i32 @putchar(i8 signext %100)
%102 = load i32, i32* %6
%103 = load i32, i32* %8
%104 = add nsw i32 %102, %103
%105 = sub nsw i32 %104, 1
%106 = load i32, i32* %7
%107 = load i32, i32* %9
%108 = add nsw i32 %106, %107
%109 = sub nsw i32 %108, 1
%110 = call i32 @gotoxy(i32 %105, i32 %109)
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 3
%112 = load i8, i8* %111
%113 = call i32 @putchar(i8 signext %112)
%114 = load i32, i32* %7
%115 = load i32, i32* %9
%116 = add nsw i32 %114, %115
%117 = add nsw i32 %116, 2
%118 = call i32 @gotoxy(i32 0, i32 %117)
br label %119
119: ; preds = %35, %47
ret void
}

LLVM IR (-O2):
define void @box(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = or i32 %1, %0
%7 = or i32 %6, %2
%8 = or i32 %7, %3
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %37
10: ; preds = %5
%11 = add nsw i32 %2, %0
%12 = tail call i32 (...) @get_screen_columns()
%13 = icmp sgt i32 %11, %12
br i1 %13, label %37, label %14
14: ; preds = %10
%15 = add nsw i32 %3, %1
%16 = tail call i32 (...) @get_screen_rows()
%17 = icmp sgt i32 %15, %16
br i1 %17, label %37, label %18
18: ; preds = %14
%19 = icmp eq i32 %4, 2
%20 = select i1 %19, i8 61, i8 45
%21 = tail call i32 @lineh(i32 %0, i32 %1, i32 %2, i8 signext %20)
%22 = add nsw i32 %15, -1
%23 = tail call i32 @lineh(i32 %0, i32 %22, i32 %2, i8 signext %20)
%24 = tail call i32 @linev(i32 %0, i32 %1, i32 %3, i8 signext 124)
%25 = add nsw i32 %11, -1
%26 = tail call i32 @linev(i32 %25, i32 %1, i32 %3, i8 signext 124)
%27 = tail call i32 @gotoxy(i32 %0, i32 %1)
%28 = tail call i32 @putchar(i8 signext 43)
%29 = tail call i32 @gotoxy(i32 %0, i32 %22)
%30 = tail call i32 @putchar(i8 signext 43)
%31 = tail call i32 @gotoxy(i32 %25, i32 %1)
%32 = tail call i32 @putchar(i8 signext 43)
%33 = tail call i32 @gotoxy(i32 %25, i32 %22)
%34 = tail call i32 @putchar(i8 signext 43)
%35 = add nsw i32 %15, 2
%36 = tail call i32 @gotoxy(i32 0, i32 %35)
br label %37
37: ; preds = %5, %10, %14, %18
ret void
}