#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);
  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
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    11a0 <transfer_escaped_string+0x40>
lea    0xe65(%rip),%rdi
call   1070 <pabort@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c4 <transfer_escaped_string+0x64>
lea    0xe5a(%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
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1195 <transfer_escaped_string+0x35>
lea    0xe70(%rip),%rdi
call   1070 <pabort@plt>
mov    %r12,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11b1 <transfer_escaped_string+0x51>
lea    0xe6d(%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 = call i64 @strlen(i8* %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = call i32* @malloc(i64 %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i64, i64* %5
%18 = call i32* @malloc(i64 %17)
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i32*, i32** %6
%25 = bitcast i32* %24 to i8*
%26 = load i8*, i8** %4
%27 = load i64, i64* %5
%28 = call i64 @unescape(i8* %25, i8* %26, i64 %27)
store i64 %28, i64* %5
%29 = load i32, i32* %3
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = load i64, i64* %5
%33 = call i32 @transfer(i32 %29, i32* %30, i32* %31, i64 %32)
%34 = load i32*, i32** %7
%35 = call i32 @free(i32* %34)
%36 = load i32*, i32** %6
%37 = call i32 @free(i32* %36)
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 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i32* @malloc(i64 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32* @malloc(i64 %3)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @pabort(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = bitcast i32* %4 to i8*
%15 = tail call i64 @unescape(i8* %14, i8* %1, i64 %3)
%16 = tail call i32 @transfer(i32 %0, i32* %4, i32* %9, i64 %15)
%17 = tail call i32 @free(i32* %9)
%18 = tail call i32 @free(i32* %4)
ret void
}