#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*/ bzero(char *, int);
int getcmd(char *, char *);
int parse_mc_cmd(char *);
int parsecmd(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int strmovetostart(char *, char *);
int checkcmd(char *nettxt, int cmdorigin, char *cmdbuffer) {
  char *start, *end;
  char command[64 + 1];
  bzero(command, 64 + 1);
  start = strchr(cmdbuffer, '<');
  end = strchr(cmdbuffer, '>');
  if (start == NULL) {
    if (cmdbuffer[0] != 0) {
      bzero(cmdbuffer, 1024);
    }
  } else {
    if (start > cmdbuffer) {
      int error = strmovetostart(cmdbuffer, start);
      if (error > 0) {
        printf("Fehler beim Säubern des gespeicherten Befehlstextes "
               "aufgetreten\n");
      }
    }
  }
  if (strlen(cmdbuffer) + strlen(nettxt) < 1024) {
    strcat(cmdbuffer, nettxt);
  } else {
    printf("Fehler: cmdbuffer ist zu klein!!!\n");
  }
  int gefunden = getcmd(cmdbuffer, command);
  while (gefunden) {
    int returnwert;
    if (cmdorigin == 1) {
      returnwert = parsecmd(command);
    } else if (cmdorigin == 2) {
      returnwert = parse_mc_cmd(command);
    }
    if (returnwert > 0) {
      return returnwert;
    } else {
      gefunden = getcmd(cmdbuffer, command);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x41,%esi
call   10a0 <bzero@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3c,%esi
call   1070 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3e,%esi
call   1070 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1206 <checkcmd+0x76>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1201 <checkcmd+0x71>
mov    -0x20(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
jmp    124a <checkcmd+0xba>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1245 <checkcmd+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strmovetostart@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jle    1240 <checkcmd+0xb0>
lea    0xdc5(%rip),%rdi
call   1080 <printf@plt>
jmp    1245 <checkcmd+0xb5>
jmp    124a <checkcmd+0xba>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%eax
add    %ecx,%eax
cmp    $0x400,%eax
jge    1289 <checkcmd+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <strcat@plt>
jmp    1295 <checkcmd+0x105>
lea    0xdb2(%rip),%rdi
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1040 <getcmd@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
je     1324 <checkcmd+0x194>
cmpl   $0x1,-0x14(%rbp)
jne    12d3 <checkcmd+0x143>
lea    -0x80(%rbp),%rdi
call   1090 <parsecmd@plt>
mov    %eax,-0x8c(%rbp)
jmp    12f1 <checkcmd+0x161>
cmpl   $0x2,-0x14(%rbp)
jne    12ec <checkcmd+0x15c>
lea    -0x80(%rbp),%rdi
call   1030 <parse_mc_cmd@plt>
mov    %eax,-0x8c(%rbp)
jmp    12f1 <checkcmd+0x161>
cmpl   $0x0,-0x8c(%rbp)
jle    130c <checkcmd+0x17c>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <checkcmd+0x19b>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1040 <getcmd@plt>
mov    %eax,-0x88(%rbp)
jmp    12a8 <checkcmd+0x118>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkcmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x41,%esi
call   10a0 <bzero@plt>
mov    %r15,%rdi
mov    $0x3c,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     11e3 <checkcmd+0x53>
cmp    %r15,%rax
jbe    11f6 <checkcmd+0x66>
mov    %r15,%rdi
mov    %rax,%rsi
call   1060 <strmovetostart@plt>
test   %eax,%eax
jle    11f6 <checkcmd+0x66>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
jmp    11f6 <checkcmd+0x66>
cmpb   $0x0,(%r15)
je     11f6 <checkcmd+0x66>
mov    %r15,%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1070 <strlen@plt>
add    %ebx,%eax
cmp    $0x3ff,%eax
jg     121e <checkcmd+0x8e>
mov    %r15,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
jmp    122a <checkcmd+0x9a>
lea    0xddb(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1050 <getcmd@plt>
test   %eax,%eax
je     1275 <checkcmd+0xe5>
mov    %rsp,%rbx
jmp    1250 <checkcmd+0xc0>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <parse_mc_cmd@plt>
test   %eax,%eax
jle    1266 <checkcmd+0xd6>
jmp    1277 <checkcmd+0xe7>
xchg   %ax,%ax
cmp    $0x2,%ebp
je     1240 <checkcmd+0xb0>
cmp    $0x1,%ebp
jne    1266 <checkcmd+0xd6>
mov    %rbx,%rdi
call   1090 <parsecmd@plt>
test   %eax,%eax
jg     1277 <checkcmd+0xe7>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <getcmd@plt>
test   %eax,%eax
jne    1250 <checkcmd+0xc0>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"Fehler beim S\C3\A4ubern des gespeicherten Befehlstextes aufgetreten\0A\00"
@.str.1 = [35 x i8] c"Fehler: cmdbuffer ist zu klein!!!\0A\00"
define i32 @checkcmd(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [65 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%14 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%15 = call i32 @bzero(i8* %14, i32 65)
%16 = load i8*, i8** %7
%17 = call i8* @strchr(i8* %16, i8 signext 60)
store i8* %17, i8** %8
%18 = load i8*, i8** %7
%19 = call i8* @strchr(i8* %18, i8 signext 62)
store i8* %19, i8** %9
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %3
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = call i32 @bzero(i8* %29, i32 1024)
br label %31
31: ; preds = %28, %22
br label %46
32: ; preds = %3
%33 = load i8*, i8** %8
%34 = load i8*, i8** %7
%35 = icmp ugt i8* %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = load i8*, i8** %8
%39 = call i32 @strmovetostart(i8* %37, i8* %38)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
br label %45
45: ; preds = %44, %32
br label %46
46: ; preds = %45, %31
%47 = load i8*, i8** %7
%48 = call i32 @strlen(i8* %47)
%49 = load i8*, i8** %5
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %48, %50
%52 = icmp slt i32 %51, 1024
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i8*, i8** %7
%55 = load i8*, i8** %5
%56 = call i32 @strcat(i8* %54, i8* %55)
br label %59
57: ; preds = %46
%58 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i8*, i8** %7
%61 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%62 = call i32 @getcmd(i8* %60, i8* %61)
store i32 %62, i32* %12
br label %63
63: ; preds = %88, %59
%64 = load i32, i32* %12
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %89
66: ; preds = %63
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%71 = call i32 @parsecmd(i8* %70)
store i32 %71, i32* %13
br label %79
72: ; preds = %66
%73 = load i32, i32* %6
%74 = icmp eq i32 %73, 2
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%77 = call i32 @parse_mc_cmd(i8* %76)
store i32 %77, i32* %13
br label %78
78: ; preds = %75, %72
br label %79
79: ; preds = %78, %69
%80 = load i32, i32* %13
%81 = icmp sgt i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = load i32, i32* %13
store i32 %83, i32* %4
br label %90
84: ; preds = %79
%85 = load i8*, i8** %7
%86 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%87 = call i32 @getcmd(i8* %85, i8* %86)
store i32 %87, i32* %12
br label %88
88: ; preds = %84
br label %63
89: ; preds = %63
store i32 0, i32* %4
br label %90
90: ; preds = %89, %82
%91 = load i32, i32* %4
ret i32 %91
}

LLVM IR (-O2):
@str = [34 x i8] c"Fehler: cmdbuffer ist zu klein!!!\00"
@str.2 = [65 x i8] c"Fehler beim S\C3\A4ubern des gespeicherten Befehlstextes aufgetreten\00"
define i32 @checkcmd(i8* %0, i32 %1, i8* %2) {
%4 = alloca [65 x i8]
%5 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 65)
%7 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 60)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i32 @bzero(i8* %2, i32 1024)
br label %21
14: ; preds = %3
%15 = icmp ugt i8* %7, %2
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = tail call i32 @strmovetostart(i8* %2, i8* %7)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.2, i64 0, i64 0))
br label %21
21: ; preds = %16, %19, %14, %9, %12
%22 = tail call i32 @strlen(i8* %2)
%23 = tail call i32 @strlen(i8* %0)
%24 = add nsw i32 %23, %22
%25 = icmp slt i32 %24, 1024
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @strcat(i8* %2, i8* %0)
br label %30
28: ; preds = %21
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
%31 = call i32 @getcmd(i8* %2, i8* %5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %44, label %33
33: ; preds = %30, %41
switch i32 %1, label %41 [
i32 1, label %34
i32 2, label %36
]
34: ; preds = %33
%35 = call i32 @parsecmd(i8* %5)
br label %38
36: ; preds = %33
%37 = call i32 @parse_mc_cmd(i8* %5)
br label %38
38: ; preds = %36, %34
%39 = phi i32 [ %35, %34 ], [ %37, %36 ]
%40 = icmp sgt i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38, %33
%42 = call i32 @getcmd(i8* %2, i8* %5)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %33
44: ; preds = %41, %38, %30
%45 = phi i32 [ 0, %30 ], [ %39, %38 ], [ 0, %41 ]
ret i32 %45
}