#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_char(int, int, char);
int /*<<< orphan*/ draw_formatted(int /*<<< orphan*/, int, char *, int);
int inside_rect(int, int, int, int, int, int);
int const rand();
int screen_height();
int screen_width();
int /*<<< orphan*/ show_screen();
void demo() {
  const int X_MAX = screen_width();
  const int Y_MAX = screen_height();
  const int LEFT = 11;
  const int MARGIN = 5;
  int left = LEFT + MARGIN + rand() % (X_MAX - LEFT - 2 * MARGIN);
  int top = MARGIN + rand() % (Y_MAX - 2 * MARGIN);
  int width = rand() % (X_MAX - left - MARGIN);
  int height = rand() % (Y_MAX - top - MARGIN);
  draw_formatted(0, 0, "left  : %d\n", left);
  draw_formatted(0, 1, "top   : %d\n", top);
  draw_formatted(0, 2, "width : %d\n", width);
  draw_formatted(0, 3, "height: %d\n", height);
  int x = left - MARGIN;
  while (x < (left + width + MARGIN)) {
    int y = top - MARGIN;
    while (y < (top + height + MARGIN)) {
      bool inside = inside_rect(x, y, left, top, width, height);
      if (inside) {
        draw_char(x, y, '+');
      } else {
        draw_char(x, y, '#');
      }
      y++;
    }
    x++;
  }
  show_screen();
}


x86 assembly (clang, -O0):
<demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1080 <screen_width@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <screen_height@plt>
mov    %eax,-0x8(%rbp)
movl   $0xb,-0xc(%rbp)
movl   $0x5,-0x10(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x4(%rbp),%ecx
sub    $0xb,%ecx
sub    $0xa,%ecx
cltd
idiv   %ecx
add    $0x10,%edx
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x8(%rbp),%ecx
sub    $0xa,%ecx
cltd
idiv   %ecx
add    $0x5,%edx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x4(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x8(%rbp),%ecx
sub    -0x18(%rbp),%ecx
sub    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
lea    0xdff(%rip),%rdx
mov    %esi,%edi
call   1060 <draw_formatted@plt>
mov    -0x18(%rbp),%ecx
xor    %edi,%edi
mov    $0x1,%esi
lea    0xdf3(%rip),%rdx
call   1060 <draw_formatted@plt>
mov    -0x1c(%rbp),%ecx
xor    %edi,%edi
mov    $0x2,%esi
lea    0xde9(%rip),%rdx
call   1060 <draw_formatted@plt>
mov    -0x20(%rbp),%ecx
xor    %edi,%edi
mov    $0x3,%esi
lea    0xddf(%rip),%rdx
call   1060 <draw_formatted@plt>
mov    -0x14(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jge    12eb <demo+0x17b>
mov    -0x18(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jge    12dd <demo+0x16d>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
call   1070 <inside_rect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     12bf <demo+0x14f>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    $0x2b,%edx
call   1050 <draw_char@plt>
jmp    12cf <demo+0x15f>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    $0x23,%edx
call   1050 <draw_char@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1270 <demo+0x100>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1253 <demo+0xe3>
mov    $0x0,%al
call   1040 <show_screen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1080 <screen_width@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <screen_height@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <rand@plt>
lea    -0x15(%rbp),%ecx
cltd
idiv   %ecx
lea    0x10(%rdx),%r14d
mov    %rdx,%r13
xor    %eax,%eax
call   1090 <rand@plt>
lea    -0xa(%rbx),%ecx
cltd
idiv   %ecx
mov    %edx,%r15d
lea    0x5(%r15),%r12d
xor    %eax,%eax
call   1090 <rand@plt>
sub    %r13d,%ebp
add    $0xffffffeb,%ebp
cltd
idiv   %ebp
mov    %edx,%ebp
xor    %eax,%eax
call   1090 <rand@plt>
sub    %r15d,%ebx
add    $0xfffffff6,%ebx
cltd
idiv   %ebx
mov    %edx,%ebx
lea    0xe1d(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %r14d,0x10(%rsp)
mov    %r14d,%ecx
call   1060 <draw_formatted@plt>
lea    0xe11(%rip),%rdx
xor    %edi,%edi
mov    $0x1,%esi
mov    %r12d,0x4(%rsp)
mov    %r12d,%ecx
call   1060 <draw_formatted@plt>
lea    0xe02(%rip),%rdx
xor    %edi,%edi
mov    $0x2,%esi
mov    %ebp,%ecx
call   1060 <draw_formatted@plt>
lea    0xdf9(%rip),%rdx
xor    %edi,%edi
mov    $0x3,%esi
mov    %rbx,0x18(%rsp)
mov    %ebx,%ecx
call   1060 <draw_formatted@plt>
mov    %r13,%rcx
mov    %ecx,%ebx
add    $0xb,%ebx
add    %ebp,%ecx
add    $0x15,%ecx
mov    %ecx,0xc(%rsp)
cmp    %ecx,%ebx
jge    12ed <demo+0x17d>
mov    0x18(%rsp),%rcx
lea    (%r15,%rcx,1),%edx
add    $0xa,%edx
mov    %edx,0x8(%rsp)
mov    %ecx,%edx
add    $0xa,%edx
mov    %r15,0x20(%rsp)
mov    %edx,0x14(%rsp)
mov    0x10(%rsp),%r13d
jmp    1289 <demo+0x119>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
je     12ed <demo+0x17d>
cmp    0x8(%rsp),%r15d
mov    0x4(%rsp),%ecx
mov    0x18(%rsp),%rax
jge    1280 <demo+0x110>
xor    %r12d,%r12d
nopl   0x0(%rax)
lea    (%r15,%r12,1),%r14d
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %ebp,%r8d
mov    %rax,%r15
mov    %r15d,%r9d
call   1070 <inside_rect@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
lea    0x23(,%rcx,8),%edx
mov    %ebx,%edi
mov    %r14d,%esi
call   1050 <draw_char@plt>
mov    %r15,%rax
mov    0x4(%rsp),%ecx
mov    0x14(%rsp),%edx
mov    0x20(%rsp),%r15
add    $0x1,%r12d
cmp    %r12d,%edx
jne    12a0 <demo+0x130>
jmp    1280 <demo+0x110>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <show_screen@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"left : %d\0A\00"
@.str.1 = [12 x i8] c"top : %d\0A\00"
@.str.2 = [12 x i8] c"width : %d\0A\00"
@.str.3 = [12 x i8] c"height: %d\0A\00"
define void @demo() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = call i32 (...) @screen_width()
store i32 %12, i32* %1
%13 = call i32 (...) @screen_height()
store i32 %13, i32* %2
store i32 11, i32* %3
store i32 5, i32* %4
%14 = call i32 (...) @rand()
%15 = load i32, i32* %1
%16 = sub nsw i32 %15, 11
%17 = sub nsw i32 %16, 10
%18 = srem i32 %14, %17
%19 = add nsw i32 16, %18
store i32 %19, i32* %5
%20 = call i32 (...) @rand()
%21 = load i32, i32* %2
%22 = sub nsw i32 %21, 10
%23 = srem i32 %20, %22
%24 = add nsw i32 5, %23
store i32 %24, i32* %6
%25 = call i32 (...) @rand()
%26 = load i32, i32* %1
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
%29 = sub nsw i32 %28, 5
%30 = srem i32 %25, %29
store i32 %30, i32* %7
%31 = call i32 (...) @rand()
%32 = load i32, i32* %2
%33 = load i32, i32* %6
%34 = sub nsw i32 %32, %33
%35 = sub nsw i32 %34, 5
%36 = srem i32 %31, %35
store i32 %36, i32* %8
%37 = load i32, i32* %5
%38 = call i32 @draw_formatted(i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %6
%40 = call i32 @draw_formatted(i32 0, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %7
%42 = call i32 @draw_formatted(i32 0, i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %8
%44 = call i32 @draw_formatted(i32 0, i32 3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %5
%46 = sub nsw i32 %45, 5
store i32 %46, i32* %9
br label %47
47: ; preds = %85, %0
%48 = load i32, i32* %9
%49 = load i32, i32* %5
%50 = load i32, i32* %7
%51 = add nsw i32 %49, %50
%52 = add nsw i32 %51, 5
%53 = icmp slt i32 %48, %52
br i1 %53, label %54, label %88
54: ; preds = %47
%55 = load i32, i32* %6
%56 = sub nsw i32 %55, 5
store i32 %56, i32* %10
br label %57
57: ; preds = %82, %54
%58 = load i32, i32* %10
%59 = load i32, i32* %6
%60 = load i32, i32* %8
%61 = add nsw i32 %59, %60
%62 = add nsw i32 %61, 5
%63 = icmp slt i32 %58, %62
br i1 %63, label %64, label %85
64: ; preds = %57
%65 = load i32, i32* %9
%66 = load i32, i32* %10
%67 = load i32, i32* %5
%68 = load i32, i32* %6
%69 = load i32, i32* %7
%70 = load i32, i32* %8
%71 = call i32 @inside_rect(i32 %65, i32 %66, i32 %67, i32 %68, i32 %69, i32 %70)
store i32 %71, i32* %11
%72 = load i32, i32* %11
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %64
%75 = load i32, i32* %9
%76 = load i32, i32* %10
%77 = call i32 @draw_char(i32 %75, i32 %76, i8 signext 43)
br label %82
78: ; preds = %64
%79 = load i32, i32* %9
%80 = load i32, i32* %10
%81 = call i32 @draw_char(i32 %79, i32 %80, i8 signext 35)
br label %82
82: ; preds = %78, %74
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 1
store i32 %84, i32* %10
br label %57
85: ; preds = %57
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
br label %47
88: ; preds = %47
%89 = call i32 (...) @show_screen()
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"left : %d\0A\00"
@.str.1 = [12 x i8] c"top : %d\0A\00"
@.str.2 = [12 x i8] c"width : %d\0A\00"
@.str.3 = [12 x i8] c"height: %d\0A\00"
define void @demo() {
%1 = tail call i32 (...) @screen_width()
%2 = tail call i32 (...) @screen_height()
%3 = tail call i32 (...) @rand()
%4 = add nsw i32 %1, -21
%5 = srem i32 %3, %4
%6 = add nsw i32 %5, 16
%7 = tail call i32 (...) @rand()
%8 = add nsw i32 %2, -10
%9 = srem i32 %7, %8
%10 = add nsw i32 %9, 5
%11 = tail call i32 (...) @rand()
%12 = sub i32 %1, %5
%13 = add i32 %12, -21
%14 = srem i32 %11, %13
%15 = tail call i32 (...) @rand()
%16 = sub i32 %2, %9
%17 = add i32 %16, -10
%18 = srem i32 %15, %17
%19 = tail call i32 @draw_formatted(i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%20 = tail call i32 @draw_formatted(i32 0, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%21 = tail call i32 @draw_formatted(i32 0, i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%22 = tail call i32 @draw_formatted(i32 0, i32 3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%23 = add nsw i32 %5, 11
%24 = add i32 %5, 21
%25 = add i32 %24, %14
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %46
27: ; preds = %0
%28 = add i32 %9, 10
%29 = add i32 %28, %18
%30 = icmp slt i32 %9, %29
%31 = add i32 %18, %9
%32 = add i32 %31, 9
br label %33
33: ; preds = %27, %43
%34 = phi i32 [ %23, %27 ], [ %44, %43 ]
br i1 %30, label %35, label %43
35: ; preds = %33, %35
%36 = phi i32 [ %41, %35 ], [ %9, %33 ]
%37 = tail call i32 @inside_rect(i32 %34, i32 %36, i32 %6, i32 %10, i32 %14, i32 %18)
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i8 35, i8 43
%40 = tail call i32 @draw_char(i32 %34, i32 %36, i8 signext %39)
%41 = add i32 %36, 1
%42 = icmp eq i32 %36, %32
br i1 %42, label %43, label %35
43: ; preds = %35, %33
%44 = add i32 %34, 1
%45 = icmp eq i32 %44, %25
br i1 %45, label %46, label %33
46: ; preds = %43, %0
%47 = tail call i32 (...) @show_screen()
ret void
}