#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*/ extractDEC(char *);
int /*<<< orphan*/ extractRA(char *);
int portRead(char *, int, int);
scalar_t__ portWrite(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int get_TemmaCurrentpos(char *local_buffer) {
  char buf[16];
  if (portWrite("E") < 0)
    return -1;
  if (portRead(local_buffer, -1, 1) == (2)) {
    if (strstr(local_buffer, "E") == local_buffer) {
      strncpy(buf, local_buffer + 1, 6);
      buf[6] = 0;
      extractRA(buf);
      strncpy(buf, local_buffer + 7, 6);
      buf[6] = 0;
      extractDEC(buf);
      return 0;
    } else {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_TemmaCurrentpos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1040 <portWrite@plt>
cmp    $0x0,%rax
jge    118e <get_TemmaCurrentpos+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <get_TemmaCurrentpos+0xc9>
mov    -0x10(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x1,%edx
call   1050 <portRead@plt>
cmp    $0x2,%eax
jne    1222 <get_TemmaCurrentpos+0xc2>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <strstr@plt>
cmp    -0x10(%rbp),%rax
jne    1216 <get_TemmaCurrentpos+0xb6>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <extractRA@plt>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x7,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x20(%rbp),%rdi
call   1070 <extractDEC@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <get_TemmaCurrentpos+0xc9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <get_TemmaCurrentpos+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_TemmaCurrentpos>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xea0(%rip),%rdi
call   1040 <portWrite@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     11cf <get_TemmaCurrentpos+0x7f>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x1,%edx
call   1050 <portRead@plt>
cmp    $0x2,%eax
jne    11cd <get_TemmaCurrentpos+0x7d>
cmpb   $0x45,(%rbx)
jne    11cf <get_TemmaCurrentpos+0x7f>
lea    0x1(%rbx),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x6(%rsp)
mov    %rbp,%rdi
call   1060 <extractRA@plt>
add    $0x7,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x6(%rsp)
mov    %rbp,%rdi
call   1070 <extractDEC@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"E\00"
define i32 @get_TemmaCurrentpos(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [16 x i8]
store i8* %0, i8** %3
%5 = call i64 @portWrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %34
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @portRead(i8* %9, i32 -1, i32 1)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %3
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @strncpy(i8* %18, i8* %20, i32 6)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
store i8 0, i8* %22
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%24 = call i32 @extractRA(i8* %23)
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 7
%28 = call i32 @strncpy(i8* %25, i8* %27, i32 6)
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
store i8 0, i8* %29
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%31 = call i32 @extractDEC(i8* %30)
store i32 0, i32* %2
br label %34
32: ; preds = %12
store i32 -1, i32* %2
br label %34
33: ; preds = %8
store i32 0, i32* %2
br label %34
34: ; preds = %33, %32, %17, %7
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"E\00"
define i32 @get_TemmaCurrentpos(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @portWrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i64 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = tail call i32 @portRead(i8* %0, i32 -1, i32 1)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 69
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = call i32 @strncpy(i8* %3, i8* %13, i32 6)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 6
store i8 0, i8* %15
%16 = call i32 @extractRA(i8* %3)
%17 = getelementptr inbounds i8, i8* %0, i64 7
%18 = call i32 @strncpy(i8* %3, i8* %17, i32 6)
store i8 0, i8* %15
%19 = call i32 @extractDEC(i8* %3)
br label %20
20: ; preds = %6, %9, %1, %12
%21 = phi i32 [ 0, %12 ], [ -1, %1 ], [ -1, %9 ], [ 0, %6 ]
ret i32 %21
}