#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 */
struct winsize {
  int ws_row;
  scalar_t__ ws_col;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ ued_get_winsize(struct winsize *);
int /*<<< orphan*/ ued_goto_lastrow();
int ued_draw_screen(void) {
  int i;
  struct winsize w;
  printf("\033[0;0H");
  printf("\033[2J");
  ued_goto_lastrow();
  ued_get_winsize(&w);
  i = w.ws_row;
  while (i != 1) {
    i--;
    printf("%s~%s", "\033[34m", "\033[0m");
    printf("\033[%d;%dH", i, 1);
    if (i == w.ws_row / 2) {
      printf("\033[%d;%dH", i - 3,
             (int)w.ws_col / 2 - (int)strlen("ued"
                                             " - "
                                             "micro editor") /
                                     2);
      printf("%s", "ued"
                   " - "
                   "micro editor");
      printf("\033[%d;%dH", i - 1, (int)w.ws_col / 2 - 1);
      printf(":)");
      printf("\033[%d;%dH", i, 1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ued_draw_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <ued_goto_lastrow@plt>
lea    -0x18(%rbp),%rdi
call   1060 <ued_get_winsize@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
je     1282 <ued_draw_screen+0x142>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
lea    0xe78(%rip),%rdi
lea    0xe77(%rip),%rsi
lea    0xe76(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    127d <ued_draw_screen+0x13d>
mov    -0x4(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
lea    0xe2a(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%esi
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%edx
sub    %eax,%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde9(%rip),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
sub    $0x1,%edx
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117a <ued_draw_screen+0x3a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ued_draw_screen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <ued_goto_lastrow@plt>
lea    0x8(%rsp),%rdi
call   1050 <ued_get_winsize@plt>
mov    0x8(%rsp),%ebx
cmp    $0x1,%ebx
jne    1185 <ued_draw_screen+0x55>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xfffffffe,%ebx
lea    0xe7d(%rip),%r14
lea    0xe7c(%rip),%r15
lea    0xe7b(%rip),%r12
lea    0xe79(%rip),%r13
jmp    11b5 <ued_draw_screen+0x85>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
jae    1174 <ued_draw_screen+0x44>
lea    0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %ecx,%ebp
jne    11b0 <ued_draw_screen+0x80>
lea    -0x2(%rbx),%esi
mov    0x10(%rsp),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
add    $0xfffffff7,%edx
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe01(%rip),%rdi
lea    0xe11(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
add    $0xffffffff,%edx
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b0 <ued_draw_screen+0x80>

LLVM IR (-O0):
%struct.winsize = type { i32, i64 }
@.str = [7 x i8] c"\1B[0;0H\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [6 x i8] c"%s~%s\00"
@.str.3 = [6 x i8] c"\1B[34m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.5 = [9 x i8] c"\1B[%d;%dH\00"
@.str.6 = [19 x i8] c"ued - micro editor\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [3 x i8] c":)\00"
define i32 @ued_draw_screen() {
%1 = alloca i32
%2 = alloca %struct.winsize
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (...) @ued_goto_lastrow()
%6 = call i32 @ued_get_winsize(%struct.winsize* %2)
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%8 = load i32, i32* %7
store i32 %8, i32* %1
br label %9
9: ; preds = %47, %0
%10 = load i32, i32* %1
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %48
12: ; preds = %9
%13 = load i32, i32* %1
%14 = add nsw i32 %13, -1
store i32 %14, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %16, i32 1)
%18 = load i32, i32* %1
%19 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 2
%22 = icmp eq i32 %18, %21
br i1 %22, label %23, label %47
23: ; preds = %12
%24 = load i32, i32* %1
%25 = sub nsw i32 %24, 3
%26 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 1
%27 = load i64, i64* %26
%28 = trunc i64 %27 to i32
%29 = sdiv i32 %28, 2
%30 = call i64 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%31 = trunc i64 %30 to i32
%32 = sdiv i32 %31, 2
%33 = sub nsw i32 %29, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* %1
%37 = sub nsw i32 %36, 1
%38 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 1
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i32
%41 = sdiv i32 %40, 2
%42 = sub nsw i32 %41, 1
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32, i32* %1
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %45, i32 1)
br label %47
47: ; preds = %23, %12
br label %9
48: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.winsize = type { i32, i64 }
@.str = [7 x i8] c"\1B[0;0H\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [6 x i8] c"%s~%s\00"
@.str.3 = [6 x i8] c"\1B[34m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.5 = [9 x i8] c"\1B[%d;%dH\00"
@.str.6 = [19 x i8] c"ued - micro editor\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [3 x i8] c":)\00"
define i32 @ued_draw_screen() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @ued_goto_lastrow()
%6 = call i32 @ued_get_winsize(%struct.winsize* %1)
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 1
br i1 %9, label %38, label %10
10: ; preds = %0
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 1
br label %12
12: ; preds = %10, %36
%13 = phi i32 [ %8, %10 ], [ %14, %36 ]
%14 = add nsw i32 %13, -1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 1)
%17 = load i32, i32* %7
%18 = sdiv i32 %17, 2
%19 = icmp eq i32 %14, %18
br i1 %19, label %20, label %36
20: ; preds = %12
%21 = add nsw i32 %13, -4
%22 = load i64, i64* %11
%23 = trunc i64 %22 to i32
%24 = sdiv i32 %23, 2
%25 = add nsw i32 %24, -9
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%28 = add nsw i32 %13, -2
%29 = load i64, i64* %11
%30 = trunc i64 %29 to i32
%31 = sdiv i32 %30, 2
%32 = add nsw i32 %31, -1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %28, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 1)
br label %36
36: ; preds = %20, %12
%37 = icmp eq i32 %14, 1
br i1 %37, label %38, label %12
38: ; preds = %36, %0
ret i32 0
}