#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 */
char OpenCM_Cmd_ReadByte();
int OpenCM_Cmd_ReadResponse(char *CmdStr, int TimeOut) {
  int cnt;
  int recv = 0;
  char Ch;
  int TimeCnt;
  cnt = 0;
  while (1) {
    Ch = OpenCM_Cmd_ReadByte();
    if (Ch == -1) {
      break;
    } else if (Ch == 0x0A) {
      CmdStr[cnt] = 0;
      recv = 1;
      break;
    } else {
      CmdStr[cnt] = Ch;
    }
    cnt++;
  }
  return recv;
}


x86 assembly (clang, -O0):
<OpenCM_Cmd_ReadResponse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <OpenCM_Cmd_ReadByte@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0xffffffff,%eax
jne    1149 <OpenCM_Cmd_ReadResponse+0x39>
jmp    118f <OpenCM_Cmd_ReadResponse+0x7f>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
jne    116e <OpenCM_Cmd_ReadResponse+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x14(%rbp)
jmp    118f <OpenCM_Cmd_ReadResponse+0x7f>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1181 <OpenCM_Cmd_ReadResponse+0x71>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <OpenCM_Cmd_ReadResponse+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenCM_Cmd_ReadResponse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <OpenCM_Cmd_ReadByte@plt>
cmp    $0xff,%al
je     1139 <OpenCM_Cmd_ReadResponse+0x29>
cmp    $0xa,%al
je     113d <OpenCM_Cmd_ReadResponse+0x2d>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    1120 <OpenCM_Cmd_ReadResponse+0x10>
xor    %eax,%eax
jmp    1149 <OpenCM_Cmd_ReadResponse+0x39>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @OpenCM_Cmd_ReadResponse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %2, %31
%10 = call signext i8 (...) @OpenCM_Cmd_ReadByte()
store i8 %10, i8* %7
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %9
br label %34
15: ; preds = %9
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
store i32 1, i32* %6
br label %34
24: ; preds = %15
%25 = load i8, i8* %7
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %9
34: ; preds = %19, %14
%35 = load i32, i32* %6
ret i32 %35
}

LLVM IR (-O2):
define i32 @OpenCM_Cmd_ReadResponse(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %9, %2
%4 = phi i64 [ %11, %9 ], [ 0, %2 ]
%5 = tail call signext i8 (...) @OpenCM_Cmd_ReadByte()
switch i8 %5, label %9 [
i8 -1, label %12
i8 10, label %6
]
6: ; preds = %3
%7 = and i64 %4, 4294967295
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
br label %12
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 %5, i8* %10
%11 = add nuw i64 %4, 1
br label %3
12: ; preds = %3, %6
%13 = phi i32 [ 1, %6 ], [ 0, %3 ]
ret i32 %13
}