#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 WRITE(int, char *, int);
int readchar(int);
int sockerror(int, char *);
int sockprint(int, char *, ...);
int do_sysreq(int fd, char key, int sysreq_fd) {
  int yn;
  if (key < 'a' || key > 'z')
    return sockprint(fd, "key out of range\r\n");
  if (sockprint(fd, "Send %c to sysreq? (y/n)\r\n", key) == -1)
    return -1;
  do {
    yn = readchar(fd);
  } while (yn != 'y' && yn != 'n' && yn != -1);
  if (yn == 'y') {
    if (WRITE(sysreq_fd, &key, 1) == -1)
      return sockerror(fd, "WRITE(sysreq_fd)");
  }
  return yn == -1 ? -1 : 0;
}


x86 assembly (clang, -O0):
<do_sysreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x61,%eax
jl     116e <do_sysreq+0x2e>
movsbl -0x9(%rbp),%eax
cmp    $0x7a,%eax
jle    1187 <do_sysreq+0x47>
mov    -0x8(%rbp),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <sockprint@plt>
mov    %eax,-0x4(%rbp)
jmp    1247 <do_sysreq+0x107>
mov    -0x8(%rbp),%edi
movsbl -0x9(%rbp),%edx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1040 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    11b1 <do_sysreq+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <do_sysreq+0x107>
jmp    11b6 <do_sysreq+0x76>
mov    -0x8(%rbp),%edi
call   1030 <readchar@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x79,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     11e9 <do_sysreq+0xa9>
xor    %eax,%eax
cmpl   $0x6e,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     11e9 <do_sysreq+0xa9>
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11b6 <do_sysreq+0x76>
cmpl   $0x79,-0x14(%rbp)
jne    1234 <do_sysreq+0xf4>
mov    -0x10(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <WRITE@plt>
cmp    $0xffffffff,%eax
jne    122f <do_sysreq+0xef>
mov    -0x8(%rbp),%edi
lea    0xe0c(%rip),%rsi
call   1060 <sockerror@plt>
mov    %eax,-0x4(%rbp)
jmp    1247 <do_sysreq+0x107>
jmp    1234 <do_sysreq+0xf4>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0xffffffff,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_sysreq>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %sil,0x7(%rsp)
lea    -0x7b(%rsi),%eax
cmp    $0xe5,%al
ja     1167 <do_sysreq+0x27>
lea    0xea8(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <sockprint@plt>
mov    %edx,%ebp
movzbl %sil,%edx
lea    0xe9f(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <sockprint@plt>
cmp    $0xffffffff,%eax
je     11de <do_sysreq+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1030 <readchar@plt>
mov    %eax,%ecx
cmp    $0xffffffff,%eax
je     11d2 <do_sysreq+0x92>
cmp    $0x6e,%ecx
je     11d2 <do_sysreq+0x92>
cmp    $0x79,%ecx
jne    1190 <do_sysreq+0x50>
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <WRITE@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11e3 <do_sysreq+0xa3>
lea    0xe65(%rip),%rsi
mov    %ebx,%edi
call   1060 <sockerror@plt>
jmp    11e3 <do_sysreq+0xa3>
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    11e3 <do_sysreq+0xa3>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"key out of range\0D\0A\00"
@.str.1 = [27 x i8] c"Send %c to sysreq? (y/n)\0D\0A\00"
@.str.2 = [17 x i8] c"WRITE(sysreq_fd)\00"
define i32 @do_sysreq(i32 %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = icmp slt i32 %10, 97
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 122
br i1 %15, label %16, label %19
16: ; preds = %12, %3
%17 = load i32, i32* %5
%18 = call i32 (i32, i8*, ...) @sockprint(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %4
br label %57
19: ; preds = %12
%20 = load i32, i32* %5
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = call i32 (i32, i8*, ...) @sockprint(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 -1, i32* %4
br label %57
26: ; preds = %19
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %5
%29 = call i32 @readchar(i32 %28)
store i32 %29, i32* %8
br label %30
30: ; preds = %27
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 121
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 110
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, -1
br label %39
39: ; preds = %36, %33, %30
%40 = phi i1 [ false, %33 ], [ false, %30 ], [ %38, %36 ]
br i1 %40, label %27, label %41
41: ; preds = %39
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, 121
br i1 %43, label %44, label %52
44: ; preds = %41
%45 = load i32, i32* %7
%46 = call i32 @WRITE(i32 %45, i8* %6, i32 1)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* %5
%50 = call i32 @sockerror(i32 %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 %50, i32* %4
br label %57
51: ; preds = %44
br label %52
52: ; preds = %51, %41
%53 = load i32, i32* %8
%54 = icmp eq i32 %53, -1
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 -1, i32 0
store i32 %56, i32* %4
br label %57
57: ; preds = %52, %48, %25, %16
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [19 x i8] c"key out of range\0D\0A\00"
@.str.1 = [27 x i8] c"Send %c to sysreq? (y/n)\0D\0A\00"
@.str.2 = [17 x i8] c"WRITE(sysreq_fd)\00"
define i32 @do_sysreq(i32 %0, i8 signext %1, i32 %2) {
%4 = alloca i8
store i8 %1, i8* %4
%5 = add i8 %1, -123
%6 = icmp ult i8 %5, -26
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %23
9: ; preds = %3
%10 = zext i8 %1 to i32
%11 = tail call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %23, label %13
13: ; preds = %9, %13
%14 = tail call i32 @readchar(i32 %0)
switch i32 %14, label %13 [
i32 121, label %15
i32 110, label %20
i32 -1, label %20
]
15: ; preds = %13
%16 = call i32 @WRITE(i32 %2, i8* %4, i32 1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %23
20: ; preds = %13, %13
%21 = icmp eq i32 %14, -1
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %15, %20, %9, %18, %7
%24 = phi i32 [ %8, %7 ], [ %19, %18 ], [ -1, %9 ], [ %22, %20 ], [ 0, %15 ]
ret i32 %24
}