#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 /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strncpy(char *, char *, int);
char *strtok(char *, char *);
int parse_reply(char *input) {
  char *next = input;
  char *retstr;
  int retint = -1;
  int inputlen = strlen(input);
  int len = 0;
  printf("Eingabe: %s\n", input);
  while (1) {
    retstr = strtok(next, " \n");
    next = NULL;
    if (retstr == NULL) {
      input[0] = 0;
      break;
    }
    len += strlen(retstr) + 1;
    if (strcmp(retstr, "key") == 0) {
      retstr = strtok(next, " \n");
      len += strlen(retstr) + 1;
      if (strcmp(retstr, "Escape") == 0)
        retint = 4;
      if (strcmp(retstr, "Down") == 0)
        retint = 1;
      if (strcmp(retstr, "Right") == 0)
        retint = 3;
      if (strcmp(retstr, "Enter") == 0)
        retint = 2;
      input = strncpy(input, &input[len], inputlen - len + 1);
      return retint;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c1 <parse_reply+0x71>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    12c8 <parse_reply+0x178>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c3 <parse_reply+0x173>
mov    -0x18(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1234 <parse_reply+0xe4>
movl   $0x4,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1255 <parse_reply+0x105>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <parse_reply+0x126>
movl   $0x3,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <parse_reply+0x147>
movl   $0x2,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
mov    -0x28(%rbp),%edx
sub    -0x2c(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12cf <parse_reply+0x17f>
jmp    118e <parse_reply+0x3e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_reply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe93(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
xor    %ebp,%ebp
lea    0xe8f(%rip),%r13
lea    0xe8b(%rip),%r12
mov    %r15,%rdi
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     1267 <parse_reply+0x117>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
mov    $0x0,%edi
test   %rax,%rax
jne    1190 <parse_reply+0x40>
lea    0xe40(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%r12d
add    $0x1,%r12d
lea    0xe26(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
neg    %rax
sbb    %ebp,%ebp
or     $0x4,%ebp
lea    0xe16(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%ebx
cmovne %ebp,%ebx
lea    0xe01(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
mov    $0x3,%ebp
cmovne %ebx,%ebp
lea    0xded(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
mov    $0x2,%ebx
cmovne %ebp,%ebx
movslq %r12d,%rax
lea    (%r15,%rax,1),%rsi
sub    %eax,%r14d
add    $0x1,%r14d
mov    %r15,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
jmp    126d <parse_reply+0x11d>
movb   $0x0,(%r15)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Eingabe: %s\0A\00"
@.str.1 = [3 x i8] c" \0A\00"
@.str.2 = [4 x i8] c"key\00"
@.str.3 = [7 x i8] c"Escape\00"
@.str.4 = [5 x i8] c"Down\00"
@.str.5 = [6 x i8] c"Right\00"
@.str.6 = [6 x i8] c"Enter\00"
define i32 @parse_reply(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
store i8* %9, i8** %4
store i32 -1, i32* %6
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
store i32 0, i32* %8
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %1, %70
%15 = load i8*, i8** %4
%16 = call i8* @strtok(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %5
store i8* null, i8** %4
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
br label %71
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %8
%27 = add nsw i32 %26, %25
store i32 %27, i32* %8
%28 = load i8*, i8** %5
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %70
31: ; preds = %22
%32 = load i8*, i8** %4
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
%39 = load i8*, i8** %5
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %31
store i32 4, i32* %6
br label %43
43: ; preds = %42, %31
%44 = load i8*, i8** %5
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 1, i32* %6
br label %48
48: ; preds = %47, %43
%49 = load i8*, i8** %5
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 3, i32* %6
br label %53
53: ; preds = %52, %48
%54 = load i8*, i8** %5
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 2, i32* %6
br label %58
58: ; preds = %57, %53
%59 = load i8*, i8** %3
%60 = load i8*, i8** %3
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = sub nsw i32 %64, %65
%67 = add nsw i32 %66, 1
%68 = call i8* @strncpy(i8* %59, i8* %63, i32 %67)
store i8* %68, i8** %3
%69 = load i32, i32* %6
store i32 %69, i32* %2
br label %72
70: ; preds = %22
br label %14
71: ; preds = %19
store i32 0, i32* %2
br label %72
72: ; preds = %71, %58
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
@.str = [13 x i8] c"Eingabe: %s\0A\00"
@.str.1 = [3 x i8] c" \0A\00"
@.str.2 = [4 x i8] c"key\00"
@.str.3 = [7 x i8] c"Escape\00"
@.str.4 = [5 x i8] c"Down\00"
@.str.5 = [6 x i8] c"Right\00"
@.str.6 = [6 x i8] c"Enter\00"
define i32 @parse_reply(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %4
4: ; preds = %10, %1
%5 = phi i8* [ %0, %1 ], [ null, %10 ]
%6 = phi i32 [ 0, %1 ], [ %13, %10 ]
%7 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %4
store i8 0, i8* %0
br label %38
10: ; preds = %4
%11 = tail call i32 @strlen(i8* %7)
%12 = add i32 %6, 1
%13 = add i32 %12, %11
%14 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %10
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @strlen(i8* %17)
%19 = add i32 %13, 1
%20 = add i32 %19, %18
%21 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 4, i32 -1
%24 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i32 1, i32 %23
%27 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32 3, i32 %26
%30 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i32 2, i32 %29
%33 = sext i32 %20 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = add i32 %2, 1
%36 = sub i32 %35, %20
%37 = tail call i8* @strncpy(i8* %0, i8* %34, i32 %36)
br label %38
38: ; preds = %9, %16
%39 = phi i32 [ 0, %9 ], [ %32, %16 ]
ret i32 %39
}