#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(size_t);
int /*<<< orphan*/ pabort(char *);
size_t strlen(char *);
int /*<<< orphan*/ transfer(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                            size_t);
size_t unescape(char *, char *, size_t);
void transfer_escaped_string(int fd, char *str) {
  size_t size = strlen(str + 1);
  uint8_t *tx;
  uint8_t *rx;
  tx = malloc(size);
  if (!tx)
    pabort("can't allocate tx buffer");
  rx = malloc(size);
  if (!rx)
    pabort("can't allocate rx buffer");
  size = unescape((char *)tx, str, size);
  transfer(fd, tx, rx, size);
  free(rx);
  free(tx);
}


x86 assembly (clang, -O0):
<transfer_escaped_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <transfer_escaped_string+0x44>
lea    0xe61(%rip),%rdi
call   1070 <pabort@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <transfer_escaped_string+0x68>
lea    0xe56(%rip),%rdi
call   1070 <pabort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <unescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1080 <transfer@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_escaped_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
lea    0x1(%rsi),%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1196 <transfer_escaped_string+0x36>
lea    0xe6f(%rip),%rdi
call   1070 <pabort@plt>
mov    %r12,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11b2 <transfer_escaped_string+0x52>
lea    0xe6c(%rip),%rdi
call   1070 <pabort@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <unescape@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1080 <transfer@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"can't allocate tx buffer\00"
@.str.1 = [25 x i8] c"can't allocate rx buffer\00"
define void @transfer_escaped_string(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i32* @malloc(i64 %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i64, i64* %5
%19 = call i32* @malloc(i64 %18)
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = load i32*, i32** %6
%26 = bitcast i32* %25 to i8*
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = call i64 @unescape(i8* %26, i8* %27, i64 %28)
store i64 %29, i64* %5
%30 = load i32, i32* %3
%31 = load i32*, i32** %6
%32 = load i32*, i32** %7
%33 = load i64, i64* %5
%34 = call i32 @transfer(i32 %30, i32* %31, i32* %32, i64 %33)
%35 = load i32*, i32** %7
%36 = call i32 @free(i32* %35)
%37 = load i32*, i32** %6
%38 = call i32 @free(i32* %37)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"can't allocate tx buffer\00"
@.str.1 = [25 x i8] c"can't allocate rx buffer\00"
define void @transfer_escaped_string(i32 %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 1
%4 = tail call i64 @strlen(i8* %3)
%5 = tail call i32* @malloc(i64 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = tail call i32* @malloc(i64 %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = bitcast i32* %5 to i8*
%16 = tail call i64 @unescape(i8* %15, i8* %1, i64 %4)
%17 = tail call i32 @transfer(i32 %0, i32* %5, i32* %10, i64 %16)
%18 = tail call i32 @free(i32* %10)
%19 = tail call i32 @free(i32* %5)
ret void
}