#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
void write_keys(char c, FILE *out_file) {
  static int last_press = 255;
  int this_press;
  int num_presses;
  if (c == '\n') {
    last_press = 255;
    return;
  }
  switch (c) {
  case 'a':
  case 'b':
  case 'c':
    this_press = 2;
    break;
  case 'd':
  case 'e':
  case 'f':
    this_press = 3;
    break;
  case 'g':
  case 'h':
  case 'i':
    this_press = 4;
    break;
  case 'j':
  case 'k':
  case 'l':
    this_press = 5;
    break;
  case 'm':
  case 'n':
  case 'o':
    this_press = 6;
    break;
  case 'p':
  case 'q':
  case 'r':
  case 's':
    this_press = 7;
    break;
  case 't':
  case 'u':
  case 'v':
    this_press = 8;
    break;
  case 'w':
  case 'x':
  case 'y':
  case 'z':
    this_press = 9;
    break;
  case ' ':
    this_press = 0;
    break;
  default:
    fprintf(stderr, "Which keys defaulted with: %c\n", c);
    break;
  }
  if (last_press == this_press)
    fprintf(out_file, " ");
  switch (c) {
  case 'a':
  case 'd':
  case 'g':
  case 'j':
  case 'm':
  case 'p':
  case 't':
  case 'w':
  case ' ':
    num_presses = 1;
    break;
  case 'b':
  case 'e':
  case 'h':
  case 'k':
  case 'n':
  case 'q':
  case 'u':
  case 'x':
    num_presses = 2;
    break;
  case 'c':
  case 'f':
  case 'i':
  case 'l':
  case 'o':
  case 'r':
  case 'v':
  case 'y':
    num_presses = 3;
    break;
  case 's':
  case 'z':
    num_presses = 4;
    break;
  default:
    fprintf(stderr, "Number of presses defaulted with: %c\n", c);
    break;
  }
  int i;
  for (i = 0; i < num_presses; i++) {
    fprintf(out_file, "%i", this_press);
  }
  last_press = this_press;
  return;
}


x86 assembly (clang, -O0):
<write_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    113e <write_keys+0x2e>
movl   $0xff,0x2eef(%rip)
jmp    12c6 <write_keys+0x1b6>
movsbl -0x1(%rbp),%eax
add    $0xffffffe0,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5a,%eax
ja     11d4 <write_keys+0xc4>
mov    -0x28(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x3,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x4,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x5,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x6,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x7,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x8,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x9,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
movl   $0x0,-0x14(%rbp)
jmp    11f0 <write_keys+0xe0>
mov    0x2e05(%rip),%rax
mov    (%rax),%rdi
movsbl -0x1(%rbp),%edx
lea    0x10ef(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e32(%rip),%eax
cmp    -0x14(%rbp),%eax
jne    1211 <write_keys+0x101>
mov    -0x10(%rbp),%rdi
lea    0x10ed(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsbl -0x1(%rbp),%eax
add    $0xffffffe0,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x5a,%eax
ja     126b <write_keys+0x15b>
mov    -0x30(%rbp),%rax
lea    0xf3a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    1287 <write_keys+0x177>
movl   $0x2,-0x18(%rbp)
jmp    1287 <write_keys+0x177>
movl   $0x3,-0x18(%rbp)
jmp    1287 <write_keys+0x177>
movl   $0x4,-0x18(%rbp)
jmp    1287 <write_keys+0x177>
mov    0x2d6e(%rip),%rax
mov    (%rax),%rdi
movsbl -0x1(%rbp),%edx
lea    0x1079(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12bd <write_keys+0x1ad>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0x1077(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    128e <write_keys+0x17e>
mov    -0x14(%rbp),%eax
mov    %eax,0x2d62(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_keys>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    $0xff,%r12d
cmp    $0xa,%r14b
je     1235 <write_keys+0x115>
mov    %rsi,%r15
mov    %r14d,%ebx
add    $0xffffffe0,%ebx
cmp    $0x5a,%ebx
ja     1257 <write_keys+0x137>
mov    $0x2,%r12d
lea    0xea6(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x7,%r12d
cmp    %r12d,0x2ec0(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x9,%r12d
cmp    %r12d,0x2eaf(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x3,%r12d
cmp    %r12d,0x2e9e(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x4,%r12d
cmp    %r12d,0x2e8d(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x5,%r12d
cmp    %r12d,0x2e7c(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x6,%r12d
cmp    %r12d,0x2e6b(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    $0x8,%r12d
cmp    %r12d,0x2e5a(%rip)
jne    11e5 <write_keys+0xc5>
mov    $0x20,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
cmp    $0x5a,%ebx
ja     1277 <write_keys+0x157>
mov    $0x1,%ebp
lea    0xf72(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x2,%ebp
jmp    1216 <write_keys+0xf6>
mov    $0x3,%ebp
jmp    1216 <write_keys+0xf6>
mov    $0x4,%ebp
lea    0x1100(%rip),%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1220 <write_keys+0x100>
mov    %r12d,0x2df4(%rip)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
cmp    %r12d,0x2de1(%rip)
je     11d8 <write_keys+0xb8>
jmp    11e5 <write_keys+0xc5>
mov    0x2d82(%rip),%rax
mov    (%rax),%rdi
lea    0x1070(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d8 <write_keys+0xb8>
mov    0x2d62(%rip),%rax
mov    (%rax),%rdi
lea    0x106f(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1235 <write_keys+0x115>

LLVM IR (-O0):
@write_keys.last_press = internal global i32 255
@stderr = global i32* null
@.str = [31 x i8] c"Which keys defaulted with: %c\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [38 x i8] c"Number of presses defaulted with: %c\0A\00"
@.str.3 = [3 x i8] c"%i\00"
define void @write_keys(i8 signext %0, i32* %1) {
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8 %0, i8* %3
store i32* %1, i32** %4
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 255, i32* @write_keys.last_press
br label %62
12: ; preds = %2
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
switch i32 %14, label %24 [
i32 97, label %15
i32 98, label %15
i32 99, label %15
i32 100, label %16
i32 101, label %16
i32 102, label %16
i32 103, label %17
i32 104, label %17
i32 105, label %17
i32 106, label %18
i32 107, label %18
i32 108, label %18
i32 109, label %19
i32 110, label %19
i32 111, label %19
i32 112, label %20
i32 113, label %20
i32 114, label %20
i32 115, label %20
i32 116, label %21
i32 117, label %21
i32 118, label %21
i32 119, label %22
i32 120, label %22
i32 121, label %22
i32 122, label %22
i32 32, label %23
]
15: ; preds = %12, %12, %12
store i32 2, i32* %5
br label %29
16: ; preds = %12, %12, %12
store i32 3, i32* %5
br label %29
17: ; preds = %12, %12, %12
store i32 4, i32* %5
br label %29
18: ; preds = %12, %12, %12
store i32 5, i32* %5
br label %29
19: ; preds = %12, %12, %12
store i32 6, i32* %5
br label %29
20: ; preds = %12, %12, %12, %12
store i32 7, i32* %5
br label %29
21: ; preds = %12, %12, %12
store i32 8, i32* %5
br label %29
22: ; preds = %12, %12, %12, %12
store i32 9, i32* %5
br label %29
23: ; preds = %12
store i32 0, i32* %5
br label %29
24: ; preds = %12
%25 = load i32*, i32** @stderr
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %23, %22, %21, %20, %19, %18, %17, %16, %15
%30 = load i32, i32* @write_keys.last_press
%31 = load i32, i32* %5
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32*, i32** %4
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %33, %29
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
switch i32 %38, label %43 [
i32 97, label %39
i32 100, label %39
i32 103, label %39
i32 106, label %39
i32 109, label %39
i32 112, label %39
i32 116, label %39
i32 119, label %39
i32 32, label %39
i32 98, label %40
i32 101, label %40
i32 104, label %40
i32 107, label %40
i32 110, label %40
i32 113, label %40
i32 117, label %40
i32 120, label %40
i32 99, label %41
i32 102, label %41
i32 105, label %41
i32 108, label %41
i32 111, label %41
i32 114, label %41
i32 118, label %41
i32 121, label %41
i32 115, label %42
i32 122, label %42
]
39: ; preds = %36, %36, %36, %36, %36, %36, %36, %36, %36
store i32 1, i32* %6
br label %48
40: ; preds = %36, %36, %36, %36, %36, %36, %36, %36
store i32 2, i32* %6
br label %48
41: ; preds = %36, %36, %36, %36, %36, %36, %36, %36
store i32 3, i32* %6
br label %48
42: ; preds = %36, %36
store i32 4, i32* %6
br label %48
43: ; preds = %36
%44 = load i32*, i32** @stderr
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %43, %42, %41, %40, %39
store i32 0, i32* %7
br label %49
49: ; preds = %57, %48
%50 = load i32, i32* %7
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32*, i32** %4
%55 = load i32, i32* %5
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %49
60: ; preds = %49
%61 = load i32, i32* %5
store i32 %61, i32* @write_keys.last_press
br label %62
62: ; preds = %60, %11
ret void
}

LLVM IR (-O2):
@write_keys.last_press = internal unnamed_addr global i32 255
@stderr = global i32* null
@.str = [31 x i8] c"Which keys defaulted with: %c\0A\00"
@.str.2 = [38 x i8] c"Number of presses defaulted with: %c\0A\00"
@.str.3 = [3 x i8] c"%i\00"
define void @write_keys(i8 signext %0, i32* nocapture %1) {
%3 = sext i8 %0 to i32
%4 = icmp eq i8 %0, 10
br i1 %4, label %39, label %5
5: ; preds = %2
switch i32 %3, label %14 [
i32 97, label %17
i32 98, label %17
i32 99, label %17
i32 100, label %6
i32 101, label %6
i32 102, label %6
i32 103, label %7
i32 104, label %7
i32 105, label %7
i32 106, label %8
i32 107, label %8
i32 108, label %8
i32 109, label %9
i32 110, label %9
i32 111, label %9
i32 112, label %10
i32 113, label %10
i32 114, label %10
i32 115, label %10
i32 116, label %11
i32 117, label %11
i32 118, label %11
i32 119, label %12
i32 120, label %12
i32 121, label %12
i32 122, label %12
i32 32, label %13
]
6: ; preds = %5, %5, %5
br label %17
7: ; preds = %5, %5, %5
br label %17
8: ; preds = %5, %5, %5
br label %17
9: ; preds = %5, %5, %5
br label %17
10: ; preds = %5, %5, %5, %5
br label %17
11: ; preds = %5, %5, %5
br label %17
12: ; preds = %5, %5, %5, %5
br label %17
13: ; preds = %5
br label %17
14: ; preds = %5
%15 = load i32*, i32** @stderr
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %21
17: ; preds = %5, %5, %5, %13, %12, %11, %10, %9, %8, %7, %6
%18 = phi i32 [ 0, %13 ], [ 9, %12 ], [ 8, %11 ], [ 7, %10 ], [ 6, %9 ], [ 5, %8 ], [ 4, %7 ], [ 3, %6 ], [ 2, %5 ], [ 2, %5 ], [ 2, %5 ]
%19 = load i32, i32* @write_keys.last_press
%20 = icmp eq i32 %19, %18
br i1 %20, label %21, label %24
21: ; preds = %14, %17
%22 = phi i32 [ undef, %14 ], [ %18, %17 ]
%23 = tail call i32 @fputc(i32 32, i32* %1)
br label %24
24: ; preds = %21, %17
%25 = phi i32 [ %22, %21 ], [ %18, %17 ]
switch i32 %3, label %29 [
i32 97, label %32
i32 100, label %32
i32 103, label %32
i32 106, label %32
i32 109, label %32
i32 112, label %32
i32 116, label %32
i32 119, label %32
i32 32, label %32
i32 98, label %26
i32 101, label %26
i32 104, label %26
i32 107, label %26
i32 110, label %26
i32 113, label %26
i32 117, label %26
i32 120, label %26
i32 99, label %27
i32 102, label %27
i32 105, label %27
i32 108, label %27
i32 111, label %27
i32 114, label %27
i32 118, label %27
i32 121, label %27
i32 115, label %28
i32 122, label %28
]
26: ; preds = %24, %24, %24, %24, %24, %24, %24, %24
br label %32
27: ; preds = %24, %24, %24, %24, %24, %24, %24, %24
br label %32
28: ; preds = %24, %24
br label %32
29: ; preds = %24
%30 = load i32*, i32** @stderr
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %3)
br label %39
32: ; preds = %24, %24, %24, %24, %24, %24, %24, %24, %24, %28, %27, %26
%33 = phi i32 [ 2, %26 ], [ 3, %27 ], [ 4, %28 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ], [ 1, %24 ]
br label %34
34: ; preds = %32, %34
%35 = phi i32 [ %37, %34 ], [ 0, %32 ]
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%37 = add nuw nsw i32 %35, 1
%38 = icmp eq i32 %37, %33
br i1 %38, label %39, label %34
39: ; preds = %34, %29, %2
%40 = phi i32 [ 255, %2 ], [ %25, %29 ], [ %25, %34 ]
store i32 %40, i32* @write_keys.last_press
ret void
}