#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 dropdownlist(char const **, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_2p_ttys(char *, int);
char *mksocket_local(char *, int);
int /*<<< orphan*/ printstr(char *);
int /*<<< orphan*/ setcurs_end();
int select_2p_tty(int x, int y) {
  const char *items[4] = {"this terminal"};
  char ttys[3][8];
  char *msg;
  int i;
  if (!get_2p_ttys(ttys[0], 3))
    return 1;
  for (i = 0; i < 3 && *ttys[i]; i++)
    items[i + 1] = ttys[i];
  i = dropdownlist(items, i + 1, 0, x, y);
  if (!i)
    return 0;
  if (i > 1 && (msg = mksocket_local(ttys[i - 2], 1))) {
    setcurs_end();
    printstr(msg);
    free(msg);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<select_2p_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2c8b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c88(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c85(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c82(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x3,%esi
call   1080 <get_2p_ttys@plt>
cmp    $0x0,%eax
jne    11bd <select_2p_tty+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <select_2p_tty+0x151>
movl   $0x0,-0x5c(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x5c(%rbp)
mov    %al,-0x5d(%rbp)
jge    11e5 <select_2p_tty+0x85>
movslq -0x5c(%rbp),%rax
movsbl -0x50(%rbp,%rax,8),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    11f5 <select_2p_tty+0x95>
jmp    121f <select_2p_tty+0xbf>
movslq -0x5c(%rbp),%rax
lea    -0x50(%rbp),%rcx
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11c4 <select_2p_tty+0x64>
lea    -0x30(%rbp),%rdi
mov    -0x5c(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
xor    %edx,%edx
call   1050 <dropdownlist@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1250 <select_2p_tty+0xf0>
movl   $0x0,-0x4(%rbp)
jmp    12b1 <select_2p_tty+0x151>
cmpl   $0x1,-0x5c(%rbp)
jle    12aa <select_2p_tty+0x14a>
mov    -0x5c(%rbp),%eax
sub    $0x2,%eax
cltq
lea    -0x50(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x1,%esi
call   1070 <mksocket_local@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     12aa <select_2p_tty+0x14a>
mov    $0x0,%al
call   1040 <setcurs_end@plt>
mov    -0x58(%rbp),%rdi
call   1060 <printstr@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b1 <select_2p_tty+0x151>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_2p_tty>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
movaps 0x2c9c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c80(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1080 <get_2p_ttys@plt>
test   %eax,%eax
je     11cd <select_2p_tty+0x6d>
cmpb   $0x0,(%rsp)
je     11d4 <select_2p_tty+0x74>
mov    %rbx,0x28(%rsp)
cmpb   $0x0,0x8(%rsp)
je     11db <select_2p_tty+0x7b>
lea    0x8(%rsp),%rax
mov    %rax,0x30(%rsp)
cmpb   $0x0,0x10(%rsp)
je     11e2 <select_2p_tty+0x82>
lea    0x10(%rsp),%rax
mov    %rax,0x38(%rsp)
mov    $0x4,%esi
jmp    11e7 <select_2p_tty+0x87>
mov    $0x1,%ebx
jmp    123f <select_2p_tty+0xdf>
mov    $0x1,%esi
jmp    11e7 <select_2p_tty+0x87>
mov    $0x2,%esi
jmp    11e7 <select_2p_tty+0x87>
mov    $0x3,%esi
lea    0x20(%rsp),%rdi
xor    %ebx,%ebx
xor    %edx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1050 <dropdownlist@plt>
test   %eax,%eax
je     123f <select_2p_tty+0xdf>
mov    $0x1,%ebx
cmp    $0x2,%eax
jl     123f <select_2p_tty+0xdf>
add    $0xfffffffe,%eax
lea    (%rsp,%rax,8),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
call   1070 <mksocket_local@plt>
test   %rax,%rax
je     123f <select_2p_tty+0xdf>
mov    %rax,%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <setcurs_end@plt>
mov    %rbp,%rdi
call   1060 <printstr@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"this terminal\00"
@__const.select_2p_tty.items = [4 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i32 0, i32 0), i8* null, i8* null, i8* null]
define i32 @select_2p_tty(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8*]
%7 = alloca [3 x [8 x i8]]
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = bitcast [4 x i8*]* %6 to i8*
%11 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %7, i64 0, i64 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%13 = call i32 @get_2p_ttys(i8* %12, i32 3)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 1, i32* %3
br label %70
16: ; preds = %2
store i32 0, i32* %9
br label %17
17: ; preds = %39, %16
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %7, i64 0, i64 %22
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %23, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br label %28
28: ; preds = %20, %17
%29 = phi i1 [ false, %17 ], [ %27, %20 ]
br i1 %29, label %30, label %42
30: ; preds = %28
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %7, i64 0, i64 %32
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %33, i64 0, i64 0
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 %37
store i8* %34, i8** %38
br label %39
39: ; preds = %30
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %17
42: ; preds = %28
%43 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = call i32 @dropdownlist(i8** %43, i32 %45, i32 0, i32 %46, i32 %47)
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %42
store i32 0, i32* %3
br label %70
52: ; preds = %42
%53 = load i32, i32* %9
%54 = icmp sgt i32 %53, 1
br i1 %54, label %55, label %69
55: ; preds = %52
%56 = load i32, i32* %9
%57 = sub nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %7, i64 0, i64 %58
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %59, i64 0, i64 0
%61 = call i8* @mksocket_local(i8* %60, i32 1)
store i8* %61, i8** %8
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %69
63: ; preds = %55
%64 = call i32 (...) @setcurs_end()
%65 = load i8*, i8** %8
%66 = call i32 @printstr(i8* %65)
%67 = load i8*, i8** %8
%68 = call i32 @free(i8* %67)
store i32 0, i32* %3
br label %70
69: ; preds = %55, %52
store i32 1, i32* %3
br label %70
70: ; preds = %69, %63, %51, %15
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [14 x i8] c"this terminal\00"
@__const.select_2p_tty.items = [4 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i32 0, i32 0), i8* null, i8* null, i8* null]
define i32 @select_2p_tty(i32 %0, i32 %1) {
%3 = alloca [4 x i8*]
%4 = alloca [3 x [8 x i8]]
%5 = bitcast [4 x i8*]* %3 to i8*
%6 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %4, i64 0, i64 0, i64 0
%7 = call i32 @get_2p_ttys(i8* %6, i32 3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %41, label %9
9: ; preds = %2
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
store i8* %6, i8** %13
%14 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %4, i64 0, i64 1, i64 0
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %12
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
store i8* %14, i8** %18
%19 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %4, i64 0, i64 2, i64 0
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
store i8* %19, i8** %23
br label %24
24: ; preds = %22, %17, %12, %9
%25 = phi i32 [ 1, %9 ], [ 2, %12 ], [ 3, %17 ], [ 4, %22 ]
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%27 = call i32 @dropdownlist(i8** %26, i32 %25, i32 0, i32 %0, i32 %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %41, label %29
29: ; preds = %24
%30 = icmp sgt i32 %27, 1
br i1 %30, label %31, label %41
31: ; preds = %29
%32 = add nsw i32 %27, -2
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [3 x [8 x i8]], [3 x [8 x i8]]* %4, i64 0, i64 %33, i64 0
%35 = call i8* @mksocket_local(i8* %34, i32 1)
%36 = icmp eq i8* %35, null
br i1 %36, label %41, label %37
37: ; preds = %31
%38 = call i32 (...) @setcurs_end()
%39 = call i32 @printstr(i8* %35)
%40 = call i32 @free(i8* %35)
br label %41
41: ; preds = %29, %31, %24, %2, %37
%42 = phi i32 [ 0, %37 ], [ 1, %2 ], [ 0, %24 ], [ 1, %31 ], [ 1, %29 ]
ret i32 %42
}