#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 */
struct serial_port {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ serial_port_read(struct serial_port *, char *, int);
bool ez_writer_read_track(struct serial_port *sport, char *track, char *tuple) {
  char byte[1];
  tuple[0] = tuple[1] = '\0';
  for (;;) {
    if (!serial_port_read(sport, byte, sizeof byte / sizeof byte[0]))
      return (false);
    if (byte[0] == '\x1b') {
      if (!serial_port_read(sport, byte, sizeof byte / sizeof byte[0]))
        return (false);
      if (byte[0] != '*')
        return (false);
      goto next_tuple;
    }
    *track++ = byte[0];
    if (byte[0] == '?') {
      goto next_tuple;
    }
  }
next_tuple:
  if (!serial_port_read(sport, byte, sizeof byte / sizeof byte[0]))
    return (false);
  tuple[0] = byte[0];
  if (!serial_port_read(sport, byte, sizeof byte / sizeof byte[0]))
    return (false);
  tuple[1] = byte[0];
  return (true);
}


x86 assembly (clang, -O0):
<ez_writer_read_track>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
cmp    $0x0,%eax
jne    115a <ez_writer_read_track+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    123f <ez_writer_read_track+0x12f>
movsbl -0x21(%rbp),%eax
cmp    $0x1b,%eax
jne    11ac <ez_writer_read_track+0x9c>
mov    -0x10(%rbp),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
cmp    $0x0,%eax
jne    118e <ez_writer_read_track+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    123f <ez_writer_read_track+0x12f>
movsbl -0x21(%rbp),%eax
cmp    $0x2a,%eax
je     11a7 <ez_writer_read_track+0x97>
movl   $0x0,-0x4(%rbp)
jmp    123f <ez_writer_read_track+0x12f>
jmp    11d7 <ez_writer_read_track+0xc7>
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movsbl -0x21(%rbp),%eax
cmp    $0x3f,%eax
jne    11d2 <ez_writer_read_track+0xc2>
jmp    11d7 <ez_writer_read_track+0xc7>
jmp    1133 <ez_writer_read_track+0x23>
mov    -0x10(%rbp),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
cmp    $0x0,%eax
jne    11fe <ez_writer_read_track+0xee>
movl   $0x0,-0x4(%rbp)
jmp    123f <ez_writer_read_track+0x12f>
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
cmp    $0x0,%eax
jne    122e <ez_writer_read_track+0x11e>
movl   $0x0,-0x4(%rbp)
jmp    123f <ez_writer_read_track+0x12f>
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ez_writer_read_track>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movw   $0x0,(%rdx)
lea    0xf(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
test   %eax,%eax
je     11c6 <ez_writer_read_track+0xb6>
movzbl 0xf(%rsp),%eax
cmp    $0x1b,%al
je     1169 <ez_writer_read_track+0x59>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0x3f,%al
jne    1140 <ez_writer_read_track+0x30>
jmp    1186 <ez_writer_read_track+0x76>
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
test   %eax,%eax
je     11c6 <ez_writer_read_track+0xb6>
cmpb   $0x2a,0xf(%rsp)
jne    11c6 <ez_writer_read_track+0xb6>
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
test   %eax,%eax
je     11c6 <ez_writer_read_track+0xb6>
mov    0xf(%rsp),%al
mov    %al,(%r14)
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1030 <serial_port_read@plt>
test   %eax,%eax
je     11c6 <ez_writer_read_track+0xb6>
mov    0xf(%rsp),%al
mov    %al,0x1(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.serial_port = type { i32 }
define i32 @ez_writer_read_track(%struct.serial_port* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.serial_port*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1 x i8]
store %struct.serial_port* %0, %struct.serial_port** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 0, i8* %10
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
br label %13
13: ; preds = %47, %3
%14 = load %struct.serial_port*, %struct.serial_port** %5
%15 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%16 = call i32 @serial_port_read(%struct.serial_port* %14, i8* %15, i32 1)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
store i32 0, i32* %4
br label %69
19: ; preds = %13
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 27
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = load %struct.serial_port*, %struct.serial_port** %5
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%27 = call i32 @serial_port_read(%struct.serial_port* %25, i8* %26, i32 1)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24
store i32 0, i32* %4
br label %69
30: ; preds = %24
%31 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 42
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 0, i32* %4
br label %69
36: ; preds = %30
br label %48
37: ; preds = %19
%38 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%39 = load i8, i8* %38
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %6
store i8 %39, i8* %40
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 63
br i1 %45, label %46, label %47
46: ; preds = %37
br label %48
47: ; preds = %37
br label %13
48: ; preds = %46, %36
%49 = load %struct.serial_port*, %struct.serial_port** %5
%50 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%51 = call i32 @serial_port_read(%struct.serial_port* %49, i8* %50, i32 1)
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %48
store i32 0, i32* %4
br label %69
54: ; preds = %48
%55 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%56 = load i8, i8* %55
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 %56, i8* %58
%59 = load %struct.serial_port*, %struct.serial_port** %5
%60 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%61 = call i32 @serial_port_read(%struct.serial_port* %59, i8* %60, i32 1)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %54
store i32 0, i32* %4
br label %69
64: ; preds = %54
%65 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%66 = load i8, i8* %65
%67 = load i8*, i8** %7
%68 = getelementptr inbounds i8, i8* %67, i64 1
store i8 %66, i8* %68
store i32 1, i32* %4
br label %69
69: ; preds = %64, %63, %53, %35, %29, %18
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
%struct.serial_port = type { i32 }
define i32 @ez_writer_read_track(%struct.serial_port* %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2) {
%4 = alloca [1 x i8]
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds i8, i8* %2, i64 1
store i8 0, i8* %6
store i8 0, i8* %2
br label %7
7: ; preds = %20, %3
%8 = phi i8* [ %1, %3 ], [ %21, %20 ]
%9 = call i32 @serial_port_read(%struct.serial_port* %0, i8* %5, i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %7
%12 = load i8, i8* %5
%13 = icmp eq i8 %12, 27
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = call i32 @serial_port_read(%struct.serial_port* %0, i8* %5, i32 1)
%16 = icmp ne i32 %15, 0
%17 = load i8, i8* %5
%18 = icmp eq i8 %17, 42
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %23, label %32
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %12, i8* %8
%22 = icmp eq i8 %12, 63
br i1 %22, label %23, label %7
23: ; preds = %20, %14
%24 = call i32 @serial_port_read(%struct.serial_port* %0, i8* %5, i32 1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i8, i8* %5
store i8 %27, i8* %2
%28 = call i32 @serial_port_read(%struct.serial_port* %0, i8* %5, i32 1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = load i8, i8* %5
store i8 %31, i8* %6
br label %32
32: ; preds = %7, %26, %23, %14, %30
%33 = phi i32 [ 1, %30 ], [ 0, %14 ], [ 0, %23 ], [ 0, %26 ], [ 0, %7 ]
ret i32 %33
}