#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_err(int /*<<< orphan*/, char *);
char *write_esc_char(char, char *);
scalar_t__ write_n(int /*<<< orphan*/, char *, int);
void locally_echo_esc(char e, char c) {
  char buf[4];
  char *p = buf;
  p = write_esc_char(e, p);
  p = write_esc_char(c, p);
  assert((p > buf) && ((size_t)(p - buf) <= sizeof(buf)));
  if (write_n(STDOUT_FILENO, buf, p - buf) < 0)
    log_err(errno, "Unable to write to stdout");
  return;
}


x86 assembly (clang, -O0):
<locally_echo_esc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
lea    -0x6(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <write_esc_char@plt>
mov    %rax,-0x10(%rbp)
mov    -0x2(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <write_esc_char@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x6(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x11(%rbp)
jbe    11ad <locally_echo_esc+0x6d>
mov    -0x10(%rbp),%rax
lea    -0x6(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
setbe  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    -0x6(%rbp),%rsi
mov    -0x10(%rbp),%rax
lea    -0x6(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <write_n@plt>
cmp    $0x0,%rax
jge    11f8 <locally_echo_esc+0xb8>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1060 <log_err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<locally_echo_esc>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rsi
call   1040 <write_esc_char@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1040 <write_esc_char@plt>
mov    %rax,%rbx
sub    %r14,%rbx
seta   %al
cmp    $0x5,%rbx
setb   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <write_n@plt>
test   %rax,%rax
jns    11a4 <locally_echo_esc+0x64>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1060 <log_err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@errno = global i32 0
@.str = [26 x i8] c"Unable to write to stdout\00"
define void @locally_echo_esc(i8 signext %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca [4 x i8]
%6 = alloca i8*
store i8 %0, i8* %3
store i8 %1, i8* %4
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8* %7, i8** %6
%8 = load i8, i8* %3
%9 = load i8*, i8** %6
%10 = call i8* @write_esc_char(i8 signext %8, i8* %9)
store i8* %10, i8** %6
%11 = load i8, i8* %4
%12 = load i8*, i8** %6
%13 = call i8* @write_esc_char(i8 signext %11, i8* %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%16 = icmp ugt i8* %14, %15
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = icmp ule i64 %22, 4
br label %24
24: ; preds = %17, %2
%25 = phi i1 [ false, %2 ], [ %23, %17 ]
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* @STDOUT_FILENO
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @write_n(i32 %28, i8* %29, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %24
%39 = load i32, i32* @errno
%40 = call i32 @log_err(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %38, %24
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@errno = global i32 0
@.str = [26 x i8] c"Unable to write to stdout\00"
define void @locally_echo_esc(i8 signext %0, i8 signext %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i8* @write_esc_char(i8 signext %0, i8* %4)
%6 = call i8* @write_esc_char(i8 signext %1, i8* %5)
%7 = icmp ugt i8* %6, %4
%8 = ptrtoint i8* %6 to i64
%9 = ptrtoint [4 x i8]* %3 to i64
%10 = sub i64 %8, %9
%11 = icmp ult i64 %10, 5
%12 = select i1 %7, i1 %11, i1 false
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* @STDOUT_FILENO
%16 = trunc i64 %10 to i32
%17 = call i64 @write_n(i32 %15, i8* %4, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = call i32 @log_err(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %2
ret void
}