#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
char getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ unlink(char *);
int main() {
  char c;
  FILE *cmd;
  initscr();
  while (1) {
    c = getch();
    if (c == '\t') {
      endwin();
      return 0;
    }
    cmd = fopen("/tmp/jakopter_user_input.sock", "w");
    fprintf(cmd, "%c\n", (int)c);
    fclose(cmd);
  }
  unlink("/tmp/jakopter_user_input.sock");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x9,%eax
jne    119c <main+0x3c>
mov    $0x0,%al
call   1070 <endwin@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x5(%rbp),%edx
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1176 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0x9,%al
je     11c1 <main+0x61>
lea    0xe7f(%rip),%r14
lea    0xe96(%rip),%r15
lea    0xe91(%rip),%r12
nop
movsbl %al,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0x9,%al
jne    1190 <main+0x30>
xor    %eax,%eax
call   1070 <endwin@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/tmp/jakopter_user_input.sock\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32 (...) @initscr()
br label %5
5: ; preds = %0, %12
%6 = call signext i8 (...) @getch()
store i8 %6, i8* %2
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 9
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = call i32 (...) @endwin()
ret i32 0
12: ; preds = %5
%13 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
br label %5
}

LLVM IR (-O2):
@.str = [30 x i8] c"/tmp/jakopter_user_input.sock\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call signext i8 (...) @getch()
%3 = icmp eq i8 %2, 9
br i1 %3, label %4, label %6
4: ; preds = %6, %0
%5 = tail call i32 (...) @endwin()
ret i32 0
6: ; preds = %0, %6
%7 = phi i8 [ %12, %6 ], [ %2, %0 ]
%8 = sext i8 %7 to i32
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%11 = tail call i32 @fclose(i32* %9)
%12 = tail call signext i8 (...) @getch()
%13 = icmp eq i8 %12, 9
br i1 %13, label %4, label %6
}