#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*/ addch(int);
int /*<<< orphan*/ clear();
int /*<<< orphan*/ print_menu();
int strlen(char *);
int print_screen(char *screen, int offset, int maxlen) {
  int i, j, c;
  int len;
  len = strlen(screen);
  clear();
  for (i = j = 0; i < len && j < maxlen + offset; i++) {
    c = screen[i];
    if (j >= offset) {
      addch(c);
    }
    if (c == '\n') {
      j++;
    }
  }
  print_menu();
  return (i >= len);
}


x86 assembly (clang, -O0):
<print_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <clear@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x20(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    1195 <print_screen+0x55>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0xc(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a5 <print_screen+0x65>
jmp    11ee <print_screen+0xae>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11c8 <print_screen+0x88>
mov    -0x1c(%rbp),%edi
call   1050 <addch@plt>
cmpl   $0xa,-0x1c(%rbp)
jne    11db <print_screen+0x9b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e0 <print_screen+0xa0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <print_screen+0x33>
mov    $0x0,%al
call   1040 <print_menu@plt>
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_screen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <clear@plt>
test   %ebx,%ebx
jle    11c6 <print_screen+0x86>
add    %r14d,%r13d
test   %r13d,%r13d
jle    11c6 <print_screen+0x86>
mov    %ebx,(%rsp)
mov    %ebx,%esi
xor    %ebp,%ebp
xor    %r15d,%r15d
mov    %r13d,0x4(%rsp)
nop
movsbl (%r12,%rbp,1),%ebx
cmp    %r14d,%r15d
jl     11a8 <print_screen+0x68>
mov    %ebx,%edi
mov    %r12,%r13
mov    %r14d,%r12d
mov    %rsi,%r14
call   1050 <addch@plt>
mov    %r14,%rsi
mov    %r12d,%r14d
mov    %r13,%r12
mov    0x4(%rsp),%r13d
xor    %eax,%eax
cmp    $0xa,%bl
sete   %cl
add    $0x1,%rbp
cmp    %rsi,%rbp
jae    11c3 <print_screen+0x83>
mov    %cl,%al
add    %eax,%r15d
cmp    %r13d,%r15d
jl     1180 <print_screen+0x40>
mov    (%rsp),%ebx
xor    %eax,%eax
call   1040 <print_menu@plt>
xor    %eax,%eax
cmp    %ebx,%ebp
setge  %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_screen(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %10
%13 = call i32 (...) @clear()
store i32 0, i32* %8
store i32 0, i32* %7
br label %14
14: ; preds = %46, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %10
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = add nsw i32 %20, %21
%23 = icmp slt i32 %19, %22
br label %24
24: ; preds = %18, %14
%25 = phi i1 [ false, %14 ], [ %23, %18 ]
br i1 %25, label %26, label %49
26: ; preds = %24
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
store i32 %32, i32* %9
%33 = load i32, i32* %8
%34 = load i32, i32* %5
%35 = icmp sge i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %26
%37 = load i32, i32* %9
%38 = call i32 @addch(i32 %37)
br label %39
39: ; preds = %36, %26
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %45
45: ; preds = %42, %39
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %14
49: ; preds = %24
%50 = call i32 (...) @print_menu()
%51 = load i32, i32* %7
%52 = load i32, i32* %10
%53 = icmp sge i32 %51, %52
%54 = zext i1 %53 to i32
ret i32 %54
}

LLVM IR (-O2):
define i32 @print_screen(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 (...) @clear()
%6 = add nsw i32 %2, %1
%7 = icmp sgt i32 %4, 0
%8 = icmp sgt i32 %6, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %31
10: ; preds = %3
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %10, %21
%13 = phi i64 [ 0, %10 ], [ %25, %21 ]
%14 = phi i32 [ 0, %10 ], [ %24, %21 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = icmp slt i32 %14, %1
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = sext i8 %16 to i32
%20 = tail call i32 @addch(i32 %19)
br label %21
21: ; preds = %18, %12
%22 = icmp eq i8 %16, 10
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %14, %23
%25 = add nuw nsw i64 %13, 1
%26 = icmp ult i64 %25, %11
%27 = icmp slt i32 %24, %6
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %12, label %29
29: ; preds = %21
%30 = trunc i64 %25 to i32
br label %31
31: ; preds = %29, %3
%32 = phi i32 [ 0, %3 ], [ %30, %29 ]
%33 = tail call i32 (...) @print_menu()
%34 = icmp sge i32 %32, %4
%35 = zext i1 %34 to i32
ret i32 %35
}