#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 */
typedef struct TYPE_10__ TYPE_1__;

/* Type definitions */
typedef int chtype;
struct TYPE_10__ {
  int _maxy;
  int _maxx;
};
typedef TYPE_1__ WINDOW;

/* Variables and functions */
int A_REVERSE;
int OK;
int /*<<< orphan*/ getyx(TYPE_1__ *, int, int);
int /*<<< orphan*/ my_wmove(TYPE_1__ *, int);
int waddch(TYPE_1__ *, int);
int /*<<< orphan*/ wdelch(TYPE_1__ *);
int winch(TYPE_1__ *);
int /*<<< orphan*/ winsch(TYPE_1__ *, int);
int /*<<< orphan*/ wmove(TYPE_1__ *, int, int);
int my_waddch(WINDOW *win, chtype c, int ins) {
  chtype ch;
  int x, y, savex, savey;
  if ((c & 0xff) != '\n')
    c = ((c & 0xff) < 32) ? ((c + 64) | A_REVERSE) : c;
  if (!ins)
    return waddch(win, c);
  else {
    getyx(win, y, x);
    savey = y;
    savex = x;
    y = win->_maxy;
    while (y > savey) {
      y--;
      wmove(win, y, win->_maxx);
      ch = winch(win);
      wdelch(win);
      y++;
      wmove(win, y, 0);
      winsch(win, ch);
      y--;
    }
    wmove(win, savey, savex);
    winsch(win, c);
    my_wmove(win, 1);
  }
  return OK;
}


x86 assembly (clang, -O0):
<my_waddch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
cmp    $0xa,%eax
je     11c7 <my_waddch+0x57>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
cmp    $0x20,%eax
jge    11bb <my_waddch+0x4b>
mov    -0x14(%rbp),%eax
add    $0x40,%eax
mov    0x2e2f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
jmp    11c1 <my_waddch+0x51>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11e5 <my_waddch+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <waddch@plt>
mov    %eax,-0x4(%rbp)
jmp    12ac <my_waddch+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <getyx@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    1277 <my_waddch+0x107>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
call   1090 <wmove@plt>
mov    -0x10(%rbp),%rdi
call   1080 <winch@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <wdelch@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
xor    %edx,%edx
call   1090 <wmove@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <winsch@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <my_waddch+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1090 <wmove@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <winsch@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <my_wmove@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_waddch>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movzbl %bl,%eax
cmp    $0xa,%eax
je     1175 <my_waddch+0x25>
lea    0x40(%rbx),%ecx
mov    0x2e75(%rip),%rsi
or     (%rsi),%ecx
cmp    $0x20,%eax
cmovae %ebx,%ecx
mov    %ecx,%ebx
test   %edx,%edx
je     11b1 <my_waddch+0x61>
mov    %r14,%rdi
call   1050 <getyx@plt>
mov    %r14,%rdi
call   1070 <wmove@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <winsch@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <my_wmove@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <waddch@plt>

LLVM IR (-O0):
%struct.TYPE_10__ = type { i32, i32 }
@A_REVERSE = global i32 0
@OK = global i32 0
define i32 @my_waddch(%struct.TYPE_10__* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_10__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.TYPE_10__* %0, %struct.TYPE_10__** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%13 = load i32, i32* %6
%14 = and i32 %13, 255
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %29
16: ; preds = %3
%17 = load i32, i32* %6
%18 = and i32 %17, 255
%19 = icmp slt i32 %18, 32
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 64
%23 = load i32, i32* @A_REVERSE
%24 = or i32 %22, %23
br label %27
25: ; preds = %16
%26 = load i32, i32* %6
br label %27
27: ; preds = %25, %20
%28 = phi i32 [ %24, %20 ], [ %26, %25 ]
store i32 %28, i32* %6
br label %29
29: ; preds = %27, %3
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%34 = load i32, i32* %6
%35 = call i32 @waddch(%struct.TYPE_10__* %33, i32 %34)
store i32 %35, i32* %4
br label %85
36: ; preds = %29
%37 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%38 = load i32, i32* %10
%39 = load i32, i32* %9
%40 = call i32 @getyx(%struct.TYPE_10__* %37, i32 %38, i32 %39)
%41 = load i32, i32* %10
store i32 %41, i32* %12
%42 = load i32, i32* %9
store i32 %42, i32* %11
%43 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%44 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %43, i32 0, i32 0
%45 = load i32, i32* %44
store i32 %45, i32* %10
br label %46
46: ; preds = %50, %36
%47 = load i32, i32* %10
%48 = load i32, i32* %12
%49 = icmp sgt i32 %47, %48
br i1 %49, label %50, label %73
50: ; preds = %46
%51 = load i32, i32* %10
%52 = add nsw i32 %51, -1
store i32 %52, i32* %10
%53 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%54 = load i32, i32* %10
%55 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%56 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %55, i32 0, i32 1
%57 = load i32, i32* %56
%58 = call i32 @wmove(%struct.TYPE_10__* %53, i32 %54, i32 %57)
%59 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%60 = call i32 @winch(%struct.TYPE_10__* %59)
store i32 %60, i32* %8
%61 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%62 = call i32 @wdelch(%struct.TYPE_10__* %61)
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
%65 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%66 = load i32, i32* %10
%67 = call i32 @wmove(%struct.TYPE_10__* %65, i32 %66, i32 0)
%68 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%69 = load i32, i32* %8
%70 = call i32 @winsch(%struct.TYPE_10__* %68, i32 %69)
%71 = load i32, i32* %10
%72 = add nsw i32 %71, -1
store i32 %72, i32* %10
br label %46
73: ; preds = %46
%74 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%75 = load i32, i32* %12
%76 = load i32, i32* %11
%77 = call i32 @wmove(%struct.TYPE_10__* %74, i32 %75, i32 %76)
%78 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%79 = load i32, i32* %6
%80 = call i32 @winsch(%struct.TYPE_10__* %78, i32 %79)
%81 = load %struct.TYPE_10__*, %struct.TYPE_10__** %5
%82 = call i32 @my_wmove(%struct.TYPE_10__* %81, i32 1)
br label %83
83: ; preds = %73
%84 = load i32, i32* @OK
store i32 %84, i32* %4
br label %85
85: ; preds = %83, %32
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
%struct.TYPE_10__ = type { i32, i32 }
@A_REVERSE = global i32 0
@OK = global i32 0
define i32 @my_waddch(%struct.TYPE_10__* %0, i32 %1, i32 %2) {
%4 = and i32 %1, 255
%5 = icmp eq i32 %4, 10
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = icmp ult i32 %4, 32
%8 = add nsw i32 %1, 64
%9 = load i32, i32* @A_REVERSE
%10 = or i32 %9, %8
%11 = select i1 %7, i32 %10, i32 %1
br label %12
12: ; preds = %6, %3
%13 = phi i32 [ %11, %6 ], [ %1, %3 ]
%14 = icmp eq i32 %2, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @waddch(%struct.TYPE_10__* %0, i32 %13)
br label %23
17: ; preds = %12
%18 = tail call i32 @getyx(%struct.TYPE_10__* %0, i32 undef, i32 undef)
%19 = tail call i32 @wmove(%struct.TYPE_10__* %0, i32 undef, i32 undef)
%20 = tail call i32 @winsch(%struct.TYPE_10__* %0, i32 %13)
%21 = tail call i32 @my_wmove(%struct.TYPE_10__* %0, i32 1)
%22 = load i32, i32* @OK
br label %23
23: ; preds = %17, %15
%24 = phi i32 [ %22, %17 ], [ %16, %15 ]
ret i32 %24
}