#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 */
char *pipe_buffer_lock();
int /*<<< orphan*/ pipe_buffer_unlock(char *, int);
int /*<<< orphan*/ write_dword(char *, int);
int /*<<< orphan*/ write_string(char *, char const *);
int sp_rtrace_write_new_library(const char *library) {
  char *_buffer = pipe_buffer_lock(), *_ptr = _buffer, *_packet_start;
  _ptr += write_dword(_ptr, ('N' | ('L' << 8) | ('I' << 16) | ('B' << 24)));
  _packet_start = (_ptr += 4, _ptr - 4);
  ;
  ;
  ;
  _ptr += write_string(_ptr, library);
  ;
  write_dword(_packet_start, _ptr - _packet_start - 4);
  ;
  ;
  pipe_buffer_unlock(_buffer, _ptr - _buffer);
  return _ptr - _buffer;
  ;
}


x86 assembly (clang, -O0):
<sp_rtrace_write_new_library>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <pipe_buffer_lock@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x42494c4e,%esi
call   1050 <write_dword@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <write_string@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x4,%rax
mov    %eax,%esi
call   1050 <write_dword@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1030 <pipe_buffer_unlock@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_rtrace_write_new_library>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <pipe_buffer_lock@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x42494c4e,%esi
call   1050 <write_dword@plt>
cltq
lea    (%r12,%rax,1),%r15
lea    (%r12,%rax,1),%rbx
add    $0x4,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <write_string@plt>
add    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <write_dword@plt>
sub    %r12d,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <pipe_buffer_unlock@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sp_rtrace_write_new_library(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* (...) @pipe_buffer_lock()
store i8* %6, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @write_dword(i8* %8, i32 1112099918)
%10 = load i8*, i8** %4
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 4
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 -4
store i8* %16, i8** %5
%17 = load i8*, i8** %4
%18 = load i8*, i8** %2
%19 = call i32 @write_string(i8* %17, i8* %18)
%20 = load i8*, i8** %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %4
%23 = load i8*, i8** %5
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = sub nsw i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i32 @write_dword(i8* %23, i32 %30)
%32 = load i8*, i8** %3
%33 = load i8*, i8** %4
%34 = load i8*, i8** %3
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = call i32 @pipe_buffer_unlock(i8* %32, i32 %38)
%40 = load i8*, i8** %4
%41 = load i8*, i8** %3
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
ret i32 %45
}

LLVM IR (-O2):
define i32 @sp_rtrace_write_new_library(i8* %0) {
%2 = tail call i8* (...) @pipe_buffer_lock()
%3 = tail call i32 @write_dword(i8* %2, i32 1112099918)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 4
%7 = getelementptr inbounds i8, i8* %6, i64 -4
%8 = tail call i32 @write_string(i8* %6, i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = ptrtoint i8* %10 to i64
%12 = tail call i32 @write_dword(i8* %7, i32 %8)
%13 = ptrtoint i8* %2 to i64
%14 = sub i64 %11, %13
%15 = trunc i64 %14 to i32
%16 = tail call i32 @pipe_buffer_unlock(i8* %2, i32 %15)
ret i32 %15
}