#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 */
scalar_t__ isprint(char);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *, int *);
char *strtok_r(char *, char const *, char **);
void parse_com(char *com) {
  const char *sep = " \t\n\r";
  char *save;
  char cmd;
  int arg, frac;
  com = strtok_r(com, sep, &save);
  while (com) {
    cmd = *com;
    if (!('A' <= cmd && cmd <= 'Z')) {
      printf("Expected G-CODE command, but get '%c' (0x%hhu)\n",
             isprint(cmd) ? cmd : ' ', cmd);
      break;
    }
    if (2 > sscanf(com + 1, "%d.%d", &arg, &frac)) {
      frac = 0;
    }
    printf("cmd='%c', arg='%d', frac='%d'\n", cmd, arg, frac);
    com = strtok_r(NULL, sep, &save);
  }
  printf("newline\n");
}


x86 assembly (clang, -O0):
<parse_com>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1248 <parse_com+0x108>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     119e <parse_com+0x5e>
movsbl -0x19(%rbp),%eax
cmp    $0x5a,%eax
jle    11e4 <parse_com+0xa4>
movsbl -0x19(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     11bd <parse_com+0x7d>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11ca <parse_com+0x8a>
mov    $0x20,%eax
mov    %eax,-0x28(%rbp)
jmp    11ca <parse_com+0x8a>
mov    -0x28(%rbp),%esi
movsbl -0x19(%rbp),%edx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1248 <parse_com+0x108>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe42(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
jle    1216 <parse_com+0xd6>
movl   $0x0,-0x24(%rbp)
movsbl -0x19(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x18(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x8(%rbp)
jmp    116c <parse_com+0x2c>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_com>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1223 <parse_com+0xd3>
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0xeb2(%rip),%r13
lea    0xe70(%rip),%rbx
lea    0x10(%rsp),%rbp
jmp    11cd <parse_com+0x7d>
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x8(%rsp)
xor    %ecx,%ecx
mov    0xc(%rsp),%edx
mov    %r13,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1223 <parse_com+0xd3>
movsbl (%rax),%r14d
lea    -0x41(%r14),%ecx
cmp    $0x1a,%cl
jae    11fe <parse_com+0xae>
add    $0x1,%rax
mov    %rax,%rdi
lea    0xe4d(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jl     11a0 <parse_com+0x50>
mov    0x8(%rsp),%ecx
jmp    11aa <parse_com+0x5a>
mov    %r14d,%edi
call   1070 <isprint@plt>
test   %rax,%rax
mov    $0x20,%esi
cmovne %r14d,%esi
lea    0xdec(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0A\0D\00"
@.str.1 = [48 x i8] c"Expected G-CODE command, but get '%c' (0x%hhu)\0A\00"
@.str.2 = [6 x i8] c"%d.%d\00"
@.str.3 = [31 x i8] c"cmd='%c', arg='%d', frac='%d'\0A\00"
@.str.4 = [9 x i8] c"newline\0A\00"
define void @parse_com(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%8 = load i8*, i8** %2
%9 = load i8*, i8** %3
%10 = call i8* @strtok_r(i8* %8, i8* %9, i8** %4)
store i8* %10, i8** %2
br label %11
11: ; preds = %43, %1
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %51
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp sle i32 65, %18
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 90
br i1 %23, label %37, label %24
24: ; preds = %20, %14
%25 = load i8, i8* %5
%26 = call i64 @isprint(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
br label %32
31: ; preds = %24
br label %32
32: ; preds = %31, %28
%33 = phi i32 [ %30, %28 ], [ 32, %31 ]
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %35)
br label %51
37: ; preds = %20
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7)
%41 = icmp sgt i32 2, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 0, i32* %7
br label %43
43: ; preds = %42, %37
%44 = load i8, i8* %5
%45 = sext i8 %44 to i32
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 %46, i32 %47)
%49 = load i8*, i8** %3
%50 = call i8* @strtok_r(i8* null, i8* %49, i8** %4)
store i8* %50, i8** %2
br label %11
51: ; preds = %32, %11
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0A\0D\00"
@.str.1 = [48 x i8] c"Expected G-CODE command, but get '%c' (0x%hhu)\0A\00"
@.str.2 = [6 x i8] c"%d.%d\00"
@.str.3 = [31 x i8] c"cmd='%c', arg='%d', frac='%d'\0A\00"
@str = [8 x i8] c"newline\00"
define void @parse_com(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i8** %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %35, label %10
10: ; preds = %1, %29
%11 = phi i8* [ %33, %29 ], [ %8, %1 ]
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = add i8 %12, -65
%15 = icmp ult i8 %14, 26
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = sext i8 %12 to i32
%18 = call i64 @isprint(i8 signext %12)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 32, i32 %17
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %17)
br label %35
22: ; preds = %10
%23 = getelementptr inbounds i8, i8* %11, i64 1
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%25 = icmp slt i32 %24, 2
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = load i32, i32* %4
br label %29
28: ; preds = %22
store i32 0, i32* %4
br label %29
29: ; preds = %26, %28
%30 = phi i32 [ %27, %26 ], [ 0, %28 ]
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %31, i32 %30)
%33 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %10
35: ; preds = %29, %1, %16
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret void
}