#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 */
size_t cgc_strlen(char const *);
int /*<<< orphan*/ read_all(char *, int);
int /*<<< orphan*/ write_string(char const *);
int sink_error(const char *buf) {
  char tmp[2];
  size_t n = cgc_strlen(buf);
  write_string("Error (invalid command): ");
  write_string(buf);
  if (n >= 1 && buf[n - 1] == '\n')
    return 1;
  tmp[1] = 0;
  do {
    if (!read_all(&tmp[0], 1))
      return 0;
    write_string(tmp);
  } while (tmp[0] != '\n');
  return 1;
}


x86 assembly (clang, -O0):
<sink_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <cgc_strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xeb0(%rip),%rdi
call   1030 <write_string@plt>
mov    -0x10(%rbp),%rdi
call   1030 <write_string@plt>
cmpq   $0x1,-0x20(%rbp)
jb     118e <sink_error+0x5e>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118e <sink_error+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <sink_error+0xa2>
movb   $0x0,-0x11(%rbp)
lea    -0x12(%rbp),%rdi
mov    $0x1,%esi
call   1050 <read_all@plt>
cmp    $0x0,%eax
jne    11b5 <sink_error+0x85>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <sink_error+0xa2>
lea    -0x12(%rbp),%rdi
call   1030 <write_string@plt>
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
jne    1192 <sink_error+0x62>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sink_error>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <cgc_strlen@plt>
mov    %rax,%r14
lea    0xeba(%rip),%rdi
call   1030 <write_string@plt>
mov    %rbx,%rdi
call   1030 <write_string@plt>
test   %r14,%r14
je     1165 <sink_error+0x35>
mov    $0x1,%eax
cmpb   $0xa,-0x1(%r14,%rbx,1)
je     1199 <sink_error+0x69>
movb   $0x0,0x7(%rsp)
lea    0x6(%rsp),%rbx
nop
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <read_all@plt>
test   %eax,%eax
je     1197 <sink_error+0x67>
mov    %rbx,%rdi
call   1030 <write_string@plt>
cmpb   $0xa,0x6(%rsp)
jne    1170 <sink_error+0x40>
mov    $0x1,%eax
jmp    1199 <sink_error+0x69>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Error (invalid command): \00"
define i32 @sink_error(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @cgc_strlen(i8* %6)
store i64 %7, i64* %5
%8 = call i32 @write_string(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i32 @write_string(i8* %9)
%11 = load i64, i64* %5
%12 = icmp uge i64 %11, 1
br i1 %12, label %13, label %22
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i64, i64* %5
%16 = sub i64 %15, 1
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 1, i32* %2
br label %38
22: ; preds = %13, %1
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %23
br label %24
24: ; preds = %32, %22
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%26 = call i32 @read_all(i8* %25, i32 1)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24
store i32 0, i32* %2
br label %38
29: ; preds = %24
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%31 = call i32 @write_string(i8* %30)
br label %32
32: ; preds = %29
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %24, label %37
37: ; preds = %32
store i32 1, i32* %2
br label %38
38: ; preds = %37, %28, %21
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [26 x i8] c"Error (invalid command): \00"
define i32 @sink_error(i8* %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @cgc_strlen(i8* %0)
%5 = tail call i32 @write_string(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @write_string(i8* %0)
%7 = icmp eq i64 %4, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = add i64 %4, -1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %22, label %13
13: ; preds = %8, %1
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %14
br label %15
15: ; preds = %18, %13
%16 = call i32 @read_all(i8* %3, i32 1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @write_string(i8* %3)
%20 = load i8, i8* %3
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %15
22: ; preds = %18, %15, %8
%23 = phi i32 [ 1, %8 ], [ 1, %18 ], [ 0, %15 ]
ret i32 %23
}