#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) <= 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    $0x10,%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),%rax
lea    -0x6(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e4b(%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    11dc <locally_echo_esc+0x9c>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <log_err@plt>
add    $0x10,%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
xor    %edi,%edi
cmp    $0x5,%rbx
setb   %dil
call   1030 <assert@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <write_n@plt>
test   %rax,%rax
jns    119f <locally_echo_esc+0x5f>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%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 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = icmp ule i64 %18, 4
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* @STDOUT_FILENO
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @write_n(i32 %22, i8* %23, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %2
%33 = load i32, i32* @errno
%34 = call i32 @log_err(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %32, %2
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 = ptrtoint i8* %6 to i64
%8 = ptrtoint [4 x i8]* %3 to i64
%9 = sub i64 %7, %8
%10 = icmp ult i64 %9, 5
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* @STDOUT_FILENO
%14 = trunc i64 %9 to i32
%15 = call i64 @write_n(i32 %13, i8* %4, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = call i32 @log_err(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %2
ret void
}