#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*/ clearbox(int, int, int, int);
int /*<<< orphan*/ drawbox(int, int, int, int, char *);
int /*<<< orphan*/ newln(int);
int /*<<< orphan*/ printstr(char const *);
int /*<<< orphan*/ put_ch(char);
int /*<<< orphan*/ setcurs(int, int);
char *strchr(char const *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int yesno_menu(int, int);
int invit_dialog(const char *user, const char *tty, int x, int y) {
  char word[7];
  const char *p = "wants to battle you. ";
  const char *q;
  int i, n;
  drawbox(x, y, 32, 7, "2P GAME INVITATION");
  setcurs(x + 2, y + 2);
  printstr(user);
  printstr(" on ");
  printstr(tty);
  i = strlen(user) + strlen(tty) + 4;
  while (*p) {
    q = strchr(p, ' ');
    n = q - p;
    if (i + n > 27) {
      newln(x + 2);
      i = 0;
    } else {
      put_ch(' ');
      i++;
    }
    strncpy(word, p, n);
    word[n] = '\0';
    printstr(word);
    i += n;
    p = q + 1;
  }
  setcurs(x + 11, y + 5);
  printstr("Accept?  ");
  i = yesno_menu(x + 20, y + 5);
  clearbox(x, y, 32, 7);
  return i;
}


x86 assembly (clang, -O0):
<invit_dialog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x20,%edx
mov    $0x7,%ecx
lea    0xe3e(%rip),%r8
call   10b0 <drawbox@plt>
mov    -0x14(%rbp),%edi
add    $0x2,%edi
mov    -0x18(%rbp),%esi
add    $0x2,%esi
call   1080 <setcurs@plt>
mov    -0x8(%rbp),%rdi
call   1070 <printstr@plt>
lea    0xe2b(%rip),%rdi
call   1070 <printstr@plt>
mov    -0x10(%rbp),%rdi
call   1070 <printstr@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     12d0 <invit_dialog+0x130>
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
cmp    $0x1b,%eax
jle    1281 <invit_dialog+0xe1>
mov    -0x14(%rbp),%edi
add    $0x2,%edi
call   1060 <newln@plt>
movl   $0x0,-0x34(%rbp)
jmp    1294 <invit_dialog+0xf4>
mov    $0x20,%edi
call   10c0 <put_ch@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x1f(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x38(%rbp),%rax
movb   $0x0,-0x1f(%rbp,%rax,1)
lea    -0x1f(%rbp),%rdi
call   1070 <printstr@plt>
mov    -0x38(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    122e <invit_dialog+0x8e>
mov    -0x14(%rbp),%edi
add    $0xb,%edi
mov    -0x18(%rbp),%esi
add    $0x5,%esi
call   1080 <setcurs@plt>
lea    0xd46(%rip),%rdi
call   1070 <printstr@plt>
mov    -0x14(%rbp),%edi
add    $0x14,%edi
mov    -0x18(%rbp),%esi
add    $0x5,%esi
call   1090 <yesno_menu@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x20,%edx
mov    $0x7,%ecx
call   10a0 <clearbox@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invit_dialog>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe57(%rip),%r8
mov    %edx,%edi
mov    %ecx,%esi
mov    $0x20,%edx
mov    $0x7,%ecx
call   10b0 <drawbox@plt>
mov    %rbp,0x8(%rsp)
lea    0x2(%rbp),%r12d
mov    %rbx,0x10(%rsp)
lea    0x2(%rbx),%esi
mov    %r12d,%edi
call   1080 <setcurs@plt>
mov    %r15,%rdi
call   1070 <printstr@plt>
lea    0xe2f(%rip),%rdi
call   1070 <printstr@plt>
mov    %r14,%rdi
call   1070 <printstr@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%r15d
add    $0x4,%r15d
lea    0xdd8(%rip),%rbp
lea    0x1(%rsp),%r13
jmp    126c <invit_dialog+0xcc>
nop
mov    $0x20,%edi
call   10c0 <put_ch@plt>
add    $0x1,%r15d
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x1(%rsp,%rax,1)
mov    %r13,%rdi
call   1070 <printstr@plt>
add    %ebx,%r15d
mov    %r14,%rbp
add    $0x1,%rbp
cmpb   $0x0,0x1(%r14)
je     1298 <invit_dialog+0xf8>
mov    %rbp,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r14
mov    %rax,%rbx
sub    %rbp,%rbx
lea    (%r15,%rbx,1),%eax
cmp    $0x1c,%eax
jl     1230 <invit_dialog+0x90>
mov    %r12d,%edi
call   1060 <newln@plt>
xor    %r15d,%r15d
jmp    123e <invit_dialog+0x9e>
mov    0x8(%rsp),%rbp
lea    0xb(%rbp),%edi
mov    0x10(%rsp),%r14
lea    0x5(%r14),%ebx
mov    %ebx,%esi
call   1080 <setcurs@plt>
lea    0xd77(%rip),%rdi
call   1070 <printstr@plt>
lea    0x14(%rbp),%edi
mov    %ebx,%esi
call   1090 <yesno_menu@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x20,%edx
mov    $0x7,%ecx
call   10a0 <clearbox@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"wants to battle you. \00"
@.str.1 = [19 x i8] c"2P GAME INVITATION\00"
@.str.2 = [5 x i8] c" on \00"
@.str.3 = [10 x i8] c"Accept? \00"
define i32 @invit_dialog(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [7 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %10
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = call i32 @drawbox(i32 %14, i32 %15, i32 32, i32 7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 2
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 2
%21 = call i32 @setcurs(i32 %18, i32 %20)
%22 = load i8*, i8** %5
%23 = call i32 @printstr(i8* %22)
%24 = call i32 @printstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = load i8*, i8** %6
%26 = call i32 @printstr(i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %31, 4
store i32 %32, i32* %12
br label %33
33: ; preds = %58, %4
%34 = load i8*, i8** %10
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %37, label %73
37: ; preds = %33
%38 = load i8*, i8** %10
%39 = call i8* @strchr(i8* %38, i8 signext 32)
store i8* %39, i8** %11
%40 = load i8*, i8** %11
%41 = load i8*, i8** %10
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
store i32 %45, i32* %13
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = add nsw i32 %46, %47
%49 = icmp sgt i32 %48, 27
br i1 %49, label %50, label %54
50: ; preds = %37
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 2
%53 = call i32 @newln(i32 %52)
store i32 0, i32* %12
br label %58
54: ; preds = %37
%55 = call i32 @put_ch(i8 signext 32)
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 1
store i32 %57, i32* %12
br label %58
58: ; preds = %54, %50
%59 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%60 = load i8*, i8** %10
%61 = load i32, i32* %13
%62 = call i32 @strncpy(i8* %59, i8* %60, i32 %61)
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 %64
store i8 0, i8* %65
%66 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%67 = call i32 @printstr(i8* %66)
%68 = load i32, i32* %13
%69 = load i32, i32* %12
%70 = add nsw i32 %69, %68
store i32 %70, i32* %12
%71 = load i8*, i8** %11
%72 = getelementptr inbounds i8, i8* %71, i64 1
store i8* %72, i8** %10
br label %33
73: ; preds = %33
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 11
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 5
%78 = call i32 @setcurs(i32 %75, i32 %77)
%79 = call i32 @printstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 20
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 5
%84 = call i32 @yesno_menu(i32 %81, i32 %83)
store i32 %84, i32* %12
%85 = load i32, i32* %7
%86 = load i32, i32* %8
%87 = call i32 @clearbox(i32 %85, i32 %86, i32 32, i32 7)
%88 = load i32, i32* %12
ret i32 %88
}

LLVM IR (-O2):
@.str = [22 x i8] c"wants to battle you. \00"
@.str.1 = [19 x i8] c"2P GAME INVITATION\00"
@.str.2 = [5 x i8] c" on \00"
@.str.3 = [10 x i8] c"Accept? \00"
define i32 @invit_dialog(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [7 x i8]
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @drawbox(i32 %2, i32 %3, i32 32, i32 7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = add nsw i32 %2, 2
%9 = add nsw i32 %3, 2
%10 = tail call i32 @setcurs(i32 %8, i32 %9)
%11 = tail call i32 @printstr(i8* %0)
%12 = tail call i32 @printstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @printstr(i8* %1)
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strlen(i8* %1)
%16 = add i32 %14, 4
%17 = add i32 %16, %15
br label %18
18: ; preds = %4, %33
%19 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %4 ], [ %41, %33 ]
%20 = phi i32 [ %17, %4 ], [ %40, %33 ]
%21 = call i8* @strchr(i8* %19, i8 signext 32)
%22 = ptrtoint i8* %21 to i64
%23 = ptrtoint i8* %19 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
%26 = add nsw i32 %20, %25
%27 = icmp sgt i32 %26, 27
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 @newln(i32 %8)
br label %33
30: ; preds = %18
%31 = call i32 @put_ch(i8 signext 32)
%32 = add nsw i32 %20, 1
br label %33
33: ; preds = %30, %28
%34 = phi i32 [ 0, %28 ], [ %32, %30 ]
%35 = call i32 @strncpy(i8* %6, i8* %19, i32 %25)
%36 = shl i64 %24, 32
%37 = ashr exact i64 %36, 32
%38 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 %37
store i8 0, i8* %38
%39 = call i32 @printstr(i8* %6)
%40 = add nsw i32 %34, %25
%41 = getelementptr inbounds i8, i8* %21, i64 1
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %18
44: ; preds = %33
%45 = add nsw i32 %2, 11
%46 = add nsw i32 %3, 5
%47 = call i32 @setcurs(i32 %45, i32 %46)
%48 = call i32 @printstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%49 = add nsw i32 %2, 20
%50 = call i32 @yesno_menu(i32 %49, i32 %46)
%51 = call i32 @clearbox(i32 %2, i32 %3, i32 32, i32 7)
ret i32 %50
}