#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 */
scalar_t__ ev_inject_keypress(int, char);
int ev_inject_keypresses(int fd, const char *msg) {
  bool escaped = false;
  for (const char *c = msg; *c; ++c) {
    char key = *c;
    if (escaped) {
      escaped = false;
      if (key == 'n') {
        if (ev_inject_keypress(fd, '\n') < 0)
          return -1;
      } else if (key == 't') {
        if (ev_inject_keypress(fd, '\t') < 0)
          return -1;
      } else {
        if (ev_inject_keypress(fd, '\\') < 0)
          return -1;
        if (ev_inject_keypress(fd, key) < 0)
          return -1;
      }
    } else if (key == '\\') {
      escaped = true;
    } else if (ev_inject_keypress(fd, key) < 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ev_inject_keypresses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     126e <ev_inject_keypresses+0x15e>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1213 <ev_inject_keypresses+0x103>
movl   $0x0,-0x14(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x6e,%eax
jne    118a <ev_inject_keypresses+0x7a>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1030 <ev_inject_keypress@plt>
cmp    $0x0,%rax
jge    1185 <ev_inject_keypresses+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <ev_inject_keypresses+0x165>
jmp    120e <ev_inject_keypresses+0xfe>
movsbl -0x21(%rbp),%eax
cmp    $0x74,%eax
jne    11bf <ev_inject_keypresses+0xaf>
mov    -0x8(%rbp),%edi
mov    $0x9,%esi
call   1030 <ev_inject_keypress@plt>
cmp    $0x0,%rax
jge    11ba <ev_inject_keypresses+0xaa>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <ev_inject_keypresses+0x165>
jmp    1209 <ev_inject_keypresses+0xf9>
mov    -0x8(%rbp),%edi
mov    $0x5c,%esi
call   1030 <ev_inject_keypress@plt>
cmp    $0x0,%rax
jge    11e2 <ev_inject_keypresses+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <ev_inject_keypresses+0x165>
mov    -0x8(%rbp),%edi
movsbl -0x21(%rbp),%esi
call   1030 <ev_inject_keypress@plt>
cmp    $0x0,%rax
jge    1204 <ev_inject_keypresses+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <ev_inject_keypresses+0x165>
jmp    1209 <ev_inject_keypresses+0xf9>
jmp    120e <ev_inject_keypresses+0xfe>
jmp    1258 <ev_inject_keypresses+0x148>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    122c <ev_inject_keypresses+0x11c>
movl   $0x1,-0x14(%rbp)
jmp    1253 <ev_inject_keypresses+0x143>
mov    -0x8(%rbp),%edi
movsbl -0x21(%rbp),%esi
call   1030 <ev_inject_keypress@plt>
cmp    $0x0,%rax
jge    124e <ev_inject_keypresses+0x13e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <ev_inject_keypresses+0x165>
jmp    1253 <ev_inject_keypresses+0x143>
jmp    1258 <ev_inject_keypresses+0x148>
jmp    125d <ev_inject_keypresses+0x14d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112e <ev_inject_keypresses+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ev_inject_keypresses>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%bl
test   %bl,%bl
je     11ca <ev_inject_keypresses+0xba>
mov    %rsi,%rbp
mov    %edi,%r14d
add    $0x1,%rbp
xor    %ecx,%ecx
mov    $0xffffffff,%r15d
jmp    1161 <ev_inject_keypresses+0x51>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%esi
call   1030 <ev_inject_keypress@plt>
xor    %ecx,%ecx
test   %rax,%rax
js     11db <ev_inject_keypresses+0xcb>
movzbl 0x0(%rbp),%ebx
add    $0x1,%rbp
test   %bl,%bl
je     11ca <ev_inject_keypresses+0xba>
test   %ecx,%ecx
je     11a0 <ev_inject_keypresses+0x90>
mov    %r14d,%edi
cmp    $0x74,%bl
je     11c0 <ev_inject_keypresses+0xb0>
cmp    $0x6e,%bl
je     1140 <ev_inject_keypresses+0x30>
mov    $0x5c,%esi
call   1030 <ev_inject_keypress@plt>
test   %rax,%rax
js     11cd <ev_inject_keypresses+0xbd>
movsbl %bl,%esi
mov    %r14d,%edi
call   1030 <ev_inject_keypress@plt>
xor    %ecx,%ecx
test   %rax,%rax
jns    1155 <ev_inject_keypresses+0x45>
jmp    11cd <ev_inject_keypresses+0xbd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%ecx
cmp    $0x5c,%bl
je     1155 <ev_inject_keypresses+0x45>
movsbl %bl,%esi
mov    %r14d,%edi
jmp    1145 <ev_inject_keypresses+0x35>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x9,%esi
jmp    1145 <ev_inject_keypresses+0x35>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r15d
jmp    11cd <ev_inject_keypresses+0xbd>

LLVM IR (-O0):
define i32 @ev_inject_keypresses(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
br label %10
10: ; preds = %67, %2
%11 = load i8*, i8** %7
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %70
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
store i8 %16, i8* %8
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %53
19: ; preds = %14
store i32 0, i32* %6
%20 = load i8, i8* %8
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 110
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i64 @ev_inject_keypress(i32 %24, i8 signext 10)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %3
br label %71
28: ; preds = %23
br label %52
29: ; preds = %19
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 116
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* %4
%35 = call i64 @ev_inject_keypress(i32 %34, i8 signext 9)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -1, i32* %3
br label %71
38: ; preds = %33
br label %51
39: ; preds = %29
%40 = load i32, i32* %4
%41 = call i64 @ev_inject_keypress(i32 %40, i8 signext 92)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 -1, i32* %3
br label %71
44: ; preds = %39
%45 = load i32, i32* %4
%46 = load i8, i8* %8
%47 = call i64 @ev_inject_keypress(i32 %45, i8 signext %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 -1, i32* %3
br label %71
50: ; preds = %44
br label %51
51: ; preds = %50, %38
br label %52
52: ; preds = %51, %28
br label %66
53: ; preds = %14
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 92
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 1, i32* %6
br label %65
58: ; preds = %53
%59 = load i32, i32* %4
%60 = load i8, i8* %8
%61 = call i64 @ev_inject_keypress(i32 %59, i8 signext %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %58
store i32 -1, i32* %3
br label %71
64: ; preds = %58
br label %65
65: ; preds = %64, %57
br label %66
66: ; preds = %65, %52
br label %67
67: ; preds = %66
%68 = load i8*, i8** %7
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %7
br label %10
70: ; preds = %10
store i32 0, i32* %3
br label %71
71: ; preds = %70, %63, %49, %43, %37, %27
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
define i32 @ev_inject_keypresses(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %33, label %5
5: ; preds = %2, %28
%6 = phi i8 [ %31, %28 ], [ %3, %2 ]
%7 = phi i8* [ %30, %28 ], [ %1, %2 ]
%8 = phi i32 [ %29, %28 ], [ 0, %2 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %5
switch i8 %6, label %17 [
i8 110, label %11
i8 116, label %14
]
11: ; preds = %10
%12 = tail call i64 @ev_inject_keypress(i32 %0, i8 signext 10)
%13 = icmp slt i64 %12, 0
br i1 %13, label %33, label %28
14: ; preds = %10
%15 = tail call i64 @ev_inject_keypress(i32 %0, i8 signext 9)
%16 = icmp slt i64 %15, 0
br i1 %16, label %33, label %28
17: ; preds = %10
%18 = tail call i64 @ev_inject_keypress(i32 %0, i8 signext 92)
%19 = icmp slt i64 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = tail call i64 @ev_inject_keypress(i32 %0, i8 signext %6)
%22 = icmp slt i64 %21, 0
br i1 %22, label %33, label %28
23: ; preds = %5
%24 = icmp eq i8 %6, 92
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = tail call i64 @ev_inject_keypress(i32 %0, i8 signext %6)
%27 = icmp slt i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %23, %25, %11, %20, %14
%29 = phi i32 [ 0, %11 ], [ 0, %14 ], [ 0, %20 ], [ 0, %25 ], [ 1, %23 ]
%30 = getelementptr inbounds i8, i8* %7, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %5
33: ; preds = %28, %11, %14, %17, %20, %25, %2
%34 = phi i32 [ 0, %2 ], [ -1, %25 ], [ -1, %20 ], [ -1, %17 ], [ -1, %14 ], [ -1, %11 ], [ 0, %28 ]
ret i32 %34
}