#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 */
int registers_length();
int remote_escape_output(void const *, int, unsigned char *, int *, int);
int write_qxfer_response(char *buf, const void *data, int len, int is_more) {
  int out_len;
  if (is_more)
    buf[0] = 'm';
  else
    buf[0] = 'l';
  return remote_escape_output(data, len, (unsigned char *)buf + 1, &out_len,
                              ((registers_length() + 32 > 2000)
                                   ? (registers_length() + 32)
                                   : 2000) -
                                  2) +
         1;
}


x86 assembly (clang, -O0):
<write_qxfer_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     114c <write_qxfer_response+0x2c>
mov    -0x8(%rbp),%rax
movb   $0x6d,(%rax)
jmp    1153 <write_qxfer_response+0x33>
mov    -0x8(%rbp),%rax
movb   $0x6c,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <registers_length@plt>
add    $0x20,%eax
cmp    $0x7d0,%eax
jle    1194 <write_qxfer_response+0x74>
mov    $0x0,%al
call   1030 <registers_length@plt>
add    $0x20,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a1 <write_qxfer_response+0x81>
mov    $0x7d0,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a1 <write_qxfer_response+0x81>
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%r8d
sub    $0x2,%r8d
lea    -0x1c(%rbp),%rcx
call   1040 <remote_escape_output@plt>
add    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_qxfer_response>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
cmp    $0x1,%ecx
mov    $0x6d,%al
sbb    $0x0,%al
mov    %al,(%rdi)
xor    %eax,%eax
call   1030 <registers_length@plt>
mov    $0x7ce,%r8d
cmp    $0x7b1,%eax
jl     115c <write_qxfer_response+0x3c>
xor    %eax,%eax
call   1030 <registers_length@plt>
mov    %eax,%r8d
add    $0x1e,%r8d
add    $0x1,%rbx
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1040 <remote_escape_output@plt>
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_qxfer_response(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 109, i8* %14
br label %18
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 108, i8* %17
br label %18
18: ; preds = %15, %12
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 (...) @registers_length()
%24 = add nsw i32 %23, 32
%25 = icmp sgt i32 %24, 2000
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 (...) @registers_length()
%28 = add nsw i32 %27, 32
br label %30
29: ; preds = %18
br label %30
30: ; preds = %29, %26
%31 = phi i32 [ %28, %26 ], [ 2000, %29 ]
%32 = sub nsw i32 %31, 2
%33 = call i32 @remote_escape_output(i8* %19, i32 %20, i8* %22, i32* %9, i32 %32)
%34 = add nsw i32 %33, 1
ret i32 %34
}

LLVM IR (-O2):
define i32 @write_qxfer_response(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32 %3, 0
%8 = select i1 %7, i8 108, i8 109
store i8 %8, i8* %0
%9 = tail call i32 (...) @registers_length()
%10 = icmp sgt i32 %9, 1968
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = tail call i32 (...) @registers_length()
%13 = add i32 %12, 30
br label %14
14: ; preds = %4, %11
%15 = phi i32 [ %13, %11 ], [ 1998, %4 ]
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = call i32 @remote_escape_output(i8* %1, i32 %2, i8* %16, i32* %5, i32 %15)
%18 = add nsw i32 %17, 1
ret i32 %18
}