#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 */
float atof(char *);
int /*<<< orphan*/ memcpy(char *, void const *, scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
char *readSonar();
int /*<<< orphan*/ setWheelSpeed(float, float);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(void const *);
char *strtok(char *, char const *);
const char *parsePacket(const void *packet) {
  char buff[1025];
  char resp[1025];
  const char dlm[] = ",";
  memcpy(buff, packet, strlen(packet) + 1);
  char *cmd = strtok(buff, dlm);
  printf("Recieved Command: %s\n", cmd);
  if (strcmp(cmd, "wheelSpeed") == 0) {
    float wheelLeft = atof(strtok(NULL, dlm));
    float wheelRight = atof(strtok(NULL, dlm));
    setWheelSpeed(wheelLeft, wheelRight);
    return "done";
  } else if (strcmp(cmd, "readSonar") == 0) {
    const char *resp = readSonar();
    return resp;
  }
}


x86 assembly (clang, -O0):
<parsePacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xe6a(%rip),%ax
mov    %ax,-0x832(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x860(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x860(%rbp),%rdi
mov    -0x858(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memcpy@plt>
lea    -0x420(%rbp),%rdi
lea    -0x832(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rsi
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
mov    -0x840(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1288 <parsePacket+0x108>
lea    -0x832(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x844(%rbp)
ff
lea    -0x832(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x848(%rbp)
ff
movss  -0x844(%rbp),%xmm0
ff
movss  -0x848(%rbp),%xmm1
ff
call   1080 <setWheelSpeed@plt>
lea    0xda4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12c8 <parsePacket+0x148>
mov    -0x840(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c3 <parsePacket+0x143>
mov    $0x0,%al
call   10a0 <readSonar@plt>
mov    %rax,-0x850(%rbp)
mov    -0x850(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c8 <parsePacket+0x148>
jmp    12c8 <parsePacket+0x148>
mov    -0x8(%rbp),%rax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsePacket>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rbx
movw   $0x2c,0xa(%rsp)
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <memcpy@plt>
lea    0xa(%rsp),%rsi
mov    %r14,%rdi
call   1090 <strtok@plt>
mov    %rax,%rbx
lea    0xe3c(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <parsePacket+0x80>
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
test   %rcx,%rcx
jne    1244 <parsePacket+0xc4>
xor    %eax,%eax
call   10a0 <readSonar@plt>
jmp    1244 <parsePacket+0xc4>
lea    0xa(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,0xc(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movaps %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
call   1080 <setWheelSpeed@plt>
lea    0xddd(%rip),%rax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.parsePacket.dlm = [2 x i8] c",\00"
@.str = [22 x i8] c"Recieved Command: %s\0A\00"
@.str.1 = [11 x i8] c"wheelSpeed\00"
@.str.2 = [5 x i8] c"done\00"
@.str.3 = [10 x i8] c"readSonar\00"
define i8* @parsePacket(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1025 x i8]
%5 = alloca [1025 x i8]
%6 = alloca [2 x i8]
%7 = alloca i8*
%8 = alloca float
%9 = alloca float
%10 = alloca i8*
store i8* %0, i8** %3
%11 = bitcast [2 x i8]* %6 to i8*
%12 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i32 @memcpy(i8* %12, i8* %13, i64 %16)
%18 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%20 = call i8* @strtok(i8* %18, i8* %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %7
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %1
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%28 = call i8* @strtok(i8* null, i8* %27)
%29 = call float @atof(i8* %28)
store float %29, float* %8
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%31 = call i8* @strtok(i8* null, i8* %30)
%32 = call float @atof(i8* %31)
store float %32, float* %9
%33 = load float, float* %8
%34 = load float, float* %9
%35 = call i32 @setWheelSpeed(float %33, float %34)
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %44
36: ; preds = %1
%37 = load i8*, i8** %7
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = call i8* (...) @readSonar()
store i8* %41, i8** %10
%42 = load i8*, i8** %10
store i8* %42, i8** %2
br label %44
43: ; preds = %36
br label %44
44: ; preds = %26, %40, %43
%45 = load i8*, i8** %2
ret i8* %45
}

LLVM IR (-O2):
@.str = [22 x i8] c"Recieved Command: %s\0A\00"
@.str.1 = [11 x i8] c"wheelSpeed\00"
@.str.2 = [5 x i8] c"done\00"
@.str.3 = [10 x i8] c"readSonar\00"
define i8* @parsePacket(i8* %0) {
%2 = alloca [1025 x i8]
%3 = alloca i16
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%5 = bitcast i16* %3 to i8*
store i16 44, i16* %3
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 1
%8 = call i32 @memcpy(i8* %4, i8* %0, i64 %7)
%9 = call i8* @strtok(i8* %4, i8* %5)
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = call i8* @strtok(i8* null, i8* %5)
%15 = call float @atof(i8* %14)
%16 = call i8* @strtok(i8* null, i8* %5)
%17 = call float @atof(i8* %16)
%18 = call i32 @setWheelSpeed(float %15, float %17)
br label %24
19: ; preds = %1
%20 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i8* (...) @readSonar()
br label %24
24: ; preds = %19, %22, %13
%25 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %13 ], [ %23, %22 ], [ undef, %19 ]
ret i8* %25
}