#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char const *const);
int write(int, char const *const, int /*<<< orphan*/);
void proc_write(const char *const data) {
  int fd = open("/proc/systemtap/attach_gdb/wrapper_path", O_WRONLY);
  if (fd == -1) {
    perror("Open proc interface");
    exit(EXIT_FAILURE);
  }
  if (write(fd, data, strlen(data)) == -1) {
    perror("Write to proc interface");
    close(fd);
    exit(EXIT_FAILURE);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<proc_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a8 <proc_write+0x48>
lea    0xe93(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11f8 <proc_write+0x98>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_write>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11aa <proc_write+0x4a>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11b8 <proc_write+0x58>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <close@plt>
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
jmp    11cb <proc_write+0x6b>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"/proc/systemtap/attach_gdb/wrapper_path\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"Open proc interface\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"Write to proc interface\00"
define void @proc_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %12
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"/proc/systemtap/attach_gdb/wrapper_path\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"Open proc interface\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"Write to proc interface\00"
define void @proc_write(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @write(i32 %3, i8* %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @close(i32 %3)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9
%19 = tail call i32 @close(i32 %3)
ret void
}