#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 */
typedef int /*<<< orphan*/ SCREEN;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ echo();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ move(int, int /*<<< orphan*/);
int /*<<< orphan*/ *newterm(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ nocbreak();
int /*<<< orphan*/ nodelay(int /*<<< orphan*/, int /*<<< orphan*/);
char *port_search();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ scrollok(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int system(char *);
void initcurses(char device[]) {
  SCREEN *newxterm;
  FILE *xterm;
  int errn, port = 0, ntries = 0, i;
  char instring[200], *tty, dev[12];
  if (strncmp(device, "curses", 6) == 0) {
    initscr();
    nocbreak();
    scrollok(stdscr, TRUE);
    nodelay(stdscr, TRUE);
    echo();
  } else if (strncmp(device, "both", 4) == 0) {
    tty = port_search();
    if (tty == NULL) {
      printf("\n");
      errn = system("xterm +sb -T \"GALFIT\" -geometry 21x6 -bg green1 -e "
                    "sleep 31536000 &");
      while (tty == NULL && ntries++ < 20) {
        printf("Trying to open up an interaction window....\n");
        system("sleep 1");
        tty = port_search();
      };
      if (tty == NULL) {
        printf("\n");
        printf("Interaction window not detected yet.  Quitting....\n");
        exit(0);
      };
    };
    strcpy(dev, tty);
    xterm = fopen(dev, "r+");
    newxterm = newterm("xterm", xterm, xterm);
    refresh();
    nodelay(stdscr, TRUE);
    echo();
    move(1, 0);
    printw("  N = New max iter \n");
    printw("  O = Output params \n");
    printw("  P = Pause fit  \n");
    printw("  Q = Quit ASAP \n");
    refresh();
    free(tty);
  };
  cbreak();
}


x86 assembly (clang, -O0):
<initcurses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    12a4 <initcurses+0x84>
mov    $0x0,%al
call   10b0 <initscr@plt>
mov    $0x0,%al
call   1120 <nocbreak@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
call   1100 <scrollok@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
call   10d0 <nodelay@plt>
mov    $0x0,%al
call   1040 <echo@plt>
jmp    1452 <initcurses+0x232>
mov    -0x8(%rbp),%rdi
lea    0xd58(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    144d <initcurses+0x22d>
mov    $0x0,%al
call   1070 <port_search@plt>
mov    %rax,-0xf8(%rbp)
cmpq   $0x0,-0xf8(%rbp)
jne    1397 <initcurses+0x177>
lea    0xe18(%rip),%rdi
call   10a0 <printf@plt>
lea    0xd1a(%rip),%rdi
call   1090 <system@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0xf8(%rbp)
mov    %al,-0x105(%rbp)
jne    1327 <initcurses+0x107>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x14,%eax
setl   %al
mov    %al,-0x105(%rbp)
mov    -0x105(%rbp),%al
test   $0x1,%al
jne    133a <initcurses+0x11a>
jmp    1365 <initcurses+0x145>
lea    0xd0f(%rip),%rdi
call   10a0 <printf@plt>
lea    0xd30(%rip),%rdi
call   1090 <system@plt>
mov    $0x0,%al
call   1070 <port_search@plt>
mov    %rax,-0xf8(%rbp)
jmp    12fa <initcurses+0xda>
cmpq   $0x0,-0xf8(%rbp)
jne    1392 <initcurses+0x172>
lea    0xd84(%rip),%rdi
call   10a0 <printf@plt>
lea    0xcff(%rip),%rdi
call   10a0 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
jmp    1397 <initcurses+0x177>
lea    -0x104(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
call   1060 <strcpy@plt>
lea    -0x104(%rbp),%rdi
lea    0xd01(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcec(%rip),%rdi
call   10e0 <newterm@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   10f0 <refresh@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
mov    0x2bf0(%rip),%rax
mov    (%rax),%esi
call   10d0 <nodelay@plt>
mov    $0x0,%al
call   1040 <echo@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1140 <move@plt>
lea    0xcb1(%rip),%rdi
call   10c0 <printw@plt>
lea    0xcba(%rip),%rdi
call   10c0 <printw@plt>
lea    0xcc4(%rip),%rdi
call   10c0 <printw@plt>
lea    0xccb(%rip),%rdi
call   10c0 <printw@plt>
mov    $0x0,%al
call   10f0 <refresh@plt>
mov    -0xf8(%rbp),%rdi
call   1030 <free@plt>
jmp    1452 <initcurses+0x232>
mov    $0x0,%al
call   1080 <cbreak@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initcurses>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xdbb(%rip),%rsi
mov    $0x6,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1385 <initcurses+0x155>
lea    0xda8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    13bc <initcurses+0x18c>
xor    %eax,%eax
call   1090 <port_search@plt>
mov    %rax,%r12
test   %rax,%rax
jne    12e2 <initcurses+0xb2>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd77(%rip),%rdi
call   10b0 <system@plt>
lea    0xe43(%rip),%r14
lea    0xda8(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <puts@plt>
mov    %r15,%rdi
call   10b0 <system@plt>
xor    %eax,%eax
call   1090 <port_search@plt>
mov    %rax,%r12
test   %rax,%rax
jne    12d9 <initcurses+0xa9>
lea    0x1(%rbx),%eax
cmp    $0x13,%ebx
mov    %eax,%ebx
jb     12b0 <initcurses+0x80>
test   %r12,%r12
je     13cf <initcurses+0x19f>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcpy@plt>
lea    0xd5f(%rip),%rsi
mov    %r14,%rdi
call   1120 <fopen@plt>
lea    0xd53(%rip),%rdi
mov    %rax,%rsi
mov    %rax,%rdx
call   10f0 <newterm@plt>
xor    %eax,%eax
call   1100 <refresh@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
call   10e0 <nodelay@plt>
xor    %eax,%eax
call   1050 <echo@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1150 <move@plt>
lea    0xd16(%rip),%rdi
call   10d0 <printw@plt>
lea    0xd1f(%rip),%rdi
call   10d0 <printw@plt>
lea    0xd29(%rip),%rdi
call   10d0 <printw@plt>
lea    0xd30(%rip),%rdi
call   10d0 <printw@plt>
xor    %eax,%eax
call   1100 <refresh@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    13bc <initcurses+0x18c>
xor    %eax,%eax
call   10c0 <initscr@plt>
xor    %eax,%eax
call   1130 <nocbreak@plt>
mov    0x2c4e(%rip),%r14
mov    (%r14),%edi
mov    0x2c3c(%rip),%rbx
mov    (%rbx),%esi
call   1110 <scrollok@plt>
mov    (%r14),%edi
mov    (%rbx),%esi
call   10e0 <nodelay@plt>
xor    %eax,%eax
call   1050 <echo@plt>
xor    %eax,%eax
call   10a0 <cbreak@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xcd1(%rip),%rdi
call   1080 <puts@plt>
xor    %edi,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"curses\00"
@stdscr = global i32 0
@TRUE = global i32 0
@.str.1 = [5 x i8] c"both\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [68 x i8] c"xterm +sb -T \22GALFIT\22 -geometry 21x6 -bg green1 -e sleep 31536000 &\00"
@.str.4 = [45 x i8] c"Trying to open up an interaction window....\0A\00"
@.str.5 = [8 x i8] c"sleep 1\00"
@.str.6 = [52 x i8] c"Interaction window not detected yet. Quitting....\0A\00"
@.str.7 = [3 x i8] c"r+\00"
@.str.8 = [6 x i8] c"xterm\00"
@.str.9 = [21 x i8] c" N = New max iter \0A\00"
@.str.10 = [22 x i8] c" O = Output params \0A\00"
@.str.11 = [19 x i8] c" P = Pause fit \0A\00"
@.str.12 = [18 x i8] c" Q = Quit ASAP \0A\00"
define void @initcurses(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [200 x i8]
%10 = alloca i8*
%11 = alloca [12 x i8]
store i8* %0, i8** %2
store i32 0, i32* %6
store i32 0, i32* %7
%12 = load i8*, i8** %2
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %1
%16 = call i32 (...) @initscr()
%17 = call i32 (...) @nocbreak()
%18 = load i32, i32* @stdscr
%19 = load i32, i32* @TRUE
%20 = call i32 @scrollok(i32 %18, i32 %19)
%21 = load i32, i32* @stdscr
%22 = load i32, i32* @TRUE
%23 = call i32 @nodelay(i32 %21, i32 %22)
%24 = call i32 (...) @echo()
br label %80
25: ; preds = %1
%26 = load i8*, i8** %2
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %79
29: ; preds = %25
%30 = call i8* (...) @port_search()
store i8* %30, i8** %10
%31 = load i8*, i8** %10
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %57
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
store i32 %35, i32* %5
br label %36
36: ; preds = %45, %33
%37 = load i8*, i8** %10
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = icmp slt i32 %40, 20
br label %43
43: ; preds = %39, %36
%44 = phi i1 [ false, %36 ], [ %42, %39 ]
br i1 %44, label %45, label %49
45: ; preds = %43
%46 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%48 = call i8* (...) @port_search()
store i8* %48, i8** %10
br label %36
49: ; preds = %43
%50 = load i8*, i8** %10
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %49
br label %57
57: ; preds = %56, %29
%58 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%59 = load i8*, i8** %10
%60 = call i32 @strcpy(i8* %58, i8* %59)
%61 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%62 = call i32* @fopen(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %62, i32** %4
%63 = load i32*, i32** %4
%64 = load i32*, i32** %4
%65 = call i32* @newterm(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32* %63, i32* %64)
store i32* %65, i32** %3
%66 = call i32 (...) @refresh()
%67 = load i32, i32* @stdscr
%68 = load i32, i32* @TRUE
%69 = call i32 @nodelay(i32 %67, i32 %68)
%70 = call i32 (...) @echo()
%71 = call i32 @move(i32 1, i32 0)
%72 = call i32 @printw(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%73 = call i32 @printw(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%74 = call i32 @printw(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%75 = call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%76 = call i32 (...) @refresh()
%77 = load i8*, i8** %10
%78 = call i32 @free(i8* %77)
br label %79
79: ; preds = %57, %25
br label %80
80: ; preds = %79, %15
%81 = call i32 (...) @cbreak()
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"curses\00"
@stdscr = global i32 0
@TRUE = global i32 0
@.str.1 = [5 x i8] c"both\00"
@.str.3 = [68 x i8] c"xterm +sb -T \22GALFIT\22 -geometry 21x6 -bg green1 -e sleep 31536000 &\00"
@.str.5 = [8 x i8] c"sleep 1\00"
@.str.7 = [3 x i8] c"r+\00"
@.str.8 = [6 x i8] c"xterm\00"
@.str.9 = [21 x i8] c" N = New max iter \0A\00"
@.str.10 = [22 x i8] c" O = Output params \0A\00"
@.str.11 = [19 x i8] c" P = Pause fit \0A\00"
@.str.12 = [18 x i8] c" Q = Quit ASAP \0A\00"
@str = [51 x i8] c"Interaction window not detected yet. Quitting....\00"
@str.13 = [44 x i8] c"Trying to open up an interaction window....\00"
define void @initcurses(i8* %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = tail call i32 (...) @initscr()
%8 = tail call i32 (...) @nocbreak()
%9 = load i32, i32* @stdscr
%10 = load i32, i32* @TRUE
%11 = tail call i32 @scrollok(i32 %9, i32 %10)
%12 = load i32, i32* @stdscr
%13 = load i32, i32* @TRUE
%14 = tail call i32 @nodelay(i32 %12, i32 %13)
%15 = tail call i32 (...) @echo()
br label %56
16: ; preds = %1
%17 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %56
19: ; preds = %16
%20 = tail call i8* (...) @port_search()
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %39
22: ; preds = %19
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %22, %25
%26 = phi i32 [ 0, %22 ], [ %27, %25 ]
%27 = add nuw nsw i32 %26, 1
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.13, i64 0, i64 0))
%29 = tail call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i8* (...) @port_search()
%31 = icmp eq i8* %30, null
%32 = icmp ult i32 %26, 19
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %25, label %34
34: ; preds = %25
br i1 %31, label %35, label %39
35: ; preds = %34
%36 = tail call i32 @putchar(i32 10)
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @exit(i32 0)
unreachable
39: ; preds = %34, %19
%40 = phi i8* [ %30, %34 ], [ %20, %19 ]
%41 = call i32 @strcpy(i8* %3, i8* %40)
%42 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32* @newterm(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32* %42, i32* %42)
%44 = call i32 (...) @refresh()
%45 = load i32, i32* @stdscr
%46 = load i32, i32* @TRUE
%47 = call i32 @nodelay(i32 %45, i32 %46)
%48 = call i32 (...) @echo()
%49 = call i32 @move(i32 1, i32 0)
%50 = call i32 @printw(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%51 = call i32 @printw(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%52 = call i32 @printw(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%53 = call i32 @printw(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%54 = call i32 (...) @refresh()
%55 = call i32 @free(i8* %40)
br label %56
56: ; preds = %16, %39, %6
%57 = call i32 (...) @cbreak()
ret void
}