#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 */
char *index(char *, char);
int strlen(char *);
char *strpbrk(char *, char *);
char *get_word(int command, char *line, int bytesRead) {
  line[bytesRead - 1] = '\0';
  char *pattern = line;
  switch (command) {
  case 108:
    pattern = index(line, 't');
    break;
  case 110:
    pattern = index(line, 'd');
    break;
  }
  pattern = strpbrk(pattern + 1, "abcdefghijklmnopqrstuvwxyz");
  char *end = strpbrk(pattern, "\t ");
  int l_p = strlen(pattern);
  int l_e = (end == NULL ? 0 : strlen(end));
  pattern[l_p - l_e] = '\0';
  return pattern;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x6c,%eax
je     1180 <get_word+0x50>
jmp    116f <get_word+0x3f>
mov    -0x34(%rbp),%eax
sub    $0x6e,%eax
je     1197 <get_word+0x67>
jmp    11a9 <get_word+0x79>
mov    -0x10(%rbp),%rdi
mov    $0x74,%esi
call   1040 <index@plt>
mov    %rax,-0x20(%rbp)
jmp    11a9 <get_word+0x79>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1040 <index@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe48(%rip),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f6 <get_word+0xc6>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    1202 <get_word+0xd2>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
movslq %edx,%rcx
movb   $0x0,-0x1(%rcx,%rsi,1)
cmp    $0x6c,%edi
je     114d <get_word+0x1d>
cmp    $0x6e,%edi
jne    115a <get_word+0x2a>
mov    $0x64,%cl
jmp    114f <get_word+0x1f>
mov    $0x74,%cl
movzbl %cl,%esi
mov    %rax,%rdi
call   1040 <index@plt>
add    $0x1,%rax
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
call   1050 <strpbrk@plt>
mov    %rax,%rbx
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
call   1050 <strpbrk@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %r14,%r14
je     119b <get_word+0x6b>
mov    %r14,%rdi
call   1030 <strlen@plt>
jmp    119d <get_word+0x6d>
xor    %eax,%eax
sub    %eax,%ebp
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [3 x i8] c"\09 \00"
define i8* @get_word(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8 0, i8* %15
%16 = load i8*, i8** %5
store i8* %16, i8** %7
%17 = load i32, i32* %4
switch i32 %17, label %24 [
i32 108, label %18
i32 110, label %21
]
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i8* @index(i8* %19, i8 signext 116)
store i8* %20, i8** %7
br label %24
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call i8* @index(i8* %22, i8 signext 100)
store i8* %23, i8** %7
br label %24
24: ; preds = %3, %21, %18
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i8* @strpbrk(i8* %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i8* @strpbrk(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %8
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %9
%32 = load i8*, i8** %8
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %24
br label %38
35: ; preds = %24
%36 = load i8*, i8** %8
%37 = call i32 @strlen(i8* %36)
br label %38
38: ; preds = %35, %34
%39 = phi i32 [ 0, %34 ], [ %37, %35 ]
store i32 %39, i32* %10
%40 = load i8*, i8** %7
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = sub nsw i32 %41, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %7
ret i8* %46
}

LLVM IR (-O2):
@.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [3 x i8] c"\09 \00"
define i8* @get_word(i32 %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 0, i8* %6
switch i32 %0, label %11 [
i32 108, label %8
i32 110, label %7
]
7: ; preds = %3
br label %8
8: ; preds = %3, %7
%9 = phi i8 [ 100, %7 ], [ 116, %3 ]
%10 = tail call i8* @index(i8* %1, i8 signext %9)
br label %11
11: ; preds = %8, %3
%12 = phi i8* [ %1, %3 ], [ %10, %8 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = tail call i8* @strpbrk(i8* %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%15 = tail call i8* @strpbrk(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @strlen(i8* %14)
%17 = icmp eq i8* %15, null
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 @strlen(i8* %15)
br label %20
20: ; preds = %11, %18
%21 = phi i32 [ %19, %18 ], [ 0, %11 ]
%22 = sub nsw i32 %16, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %14, i64 %23
store i8 0, i8* %24
ret i8* %14
}