#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int set_sting_pid(pid_t pid) {
  int fd;
  char pid_buf[6];
  fd = open("/sys/kernel/debug/sting_monitor_pid", O_RDWR);
  if (fd < 0) {
    printf("Error opening %s\n", "/sys/kernel/debug/sting_monitor_pid");
    exit(0);
  }
  sprintf(pid_buf, "%d", pid);
  write(fd, pid_buf, 6);
}


x86 assembly (clang, -O0):
<set_sting_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1197 <set_sting_pid+0x47>
lea    0xea0(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe91(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sting_pid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11a3 <set_sting_pid+0x53>
mov    %eax,%ebp
lea    0xeba(%rip),%rsi
lea    0xa(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe7a(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/kernel/debug/sting_monitor_pid\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @set_sting_pid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 6)
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/kernel/debug/sting_monitor_pid\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @set_sting_pid(i32 %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%12 = call i32 @write(i32 %5, i8* %3, i32 6)
ret i32 undef
}