#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*/ pid_t;
typedef int /*<<< orphan*/ cgroup_path;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ close(int);
scalar_t__ dprintf(int, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ getpid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int join_cgroup(char *path) {
  int fd, rc = 0;
  pid_t pid = getpid();
  char cgroup_path[PATH_MAX + 1];
  snprintf(cgroup_path, sizeof(cgroup_path), "%s/cgroup.procs", path);
  fd = open(cgroup_path, O_WRONLY);
  if (fd < 0) {
    fprintf(stderr,
            "(%s:%d: errno: %s) "
            "Opening Cgroup"
            "\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/williamfdevine/PrettyLinux/refs/heads/"
            "master/samples/bpf/test_current_task_under_cgroup_user.c",
            43, (errno == 0 ? "None" : strerror(errno)));
    return 1;
  }
  if (dprintf(fd, "%d\n", pid) < 0) {
    fprintf(stderr,
            "(%s:%d: errno: %s) "
            "Joining Cgroup"
            "\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/williamfdevine/PrettyLinux/refs/heads/"
            "master/samples/bpf/test_current_task_under_cgroup_user.c",
            49, (errno == 0 ? "None" : strerror(errno)));
    rc = 1;
  }
  close(fd);
  return rc;
}


x86 assembly (clang, -O0):
<join_cgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe37(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    125f <join_cgroup+0xef>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dd0(%rip),%rax
cmpq   $0x0,(%rax)
jne    121a <join_cgroup+0xaa>
lea    0xedb(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    122d <join_cgroup+0xbd>
mov    0x2daf(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%r8
lea    0xdd5(%rip),%rsi
lea    0xdf1(%rip),%rdx
mov    $0x2b,%ecx
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12f6 <join_cgroup+0x186>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    0xe85(%rip),%rsi
call   1060 <dprintf@plt>
cmp    $0x0,%rax
jge    12e1 <join_cgroup+0x171>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d42(%rip),%rax
cmpq   $0x0,(%rax)
jne    12a8 <join_cgroup+0x138>
lea    0xe4d(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    12bb <join_cgroup+0x14b>
mov    0x2d21(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x60(%rbp),%r8
lea    0xe2c(%rip),%rsi
lea    0xd63(%rip),%rdx
mov    $0x31,%ecx
call   1070 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_cgroup>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe51(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
call   1040 <snprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     120e <join_cgroup+0x9e>
mov    %eax,%ebx
lea    0xf19(%rip),%rsi
mov    %eax,%edi
mov    %r15d,%edx
call   1060 <dprintf@plt>
test   %rax,%rax
jns    1281 <join_cgroup+0x111>
mov    0x2de6(%rip),%rax
mov    (%rax),%r14d
mov    0x2dd4(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1259 <join_cgroup+0xe9>
call   1090 <strerror@plt>
mov    %rax,%r8
jmp    1260 <join_cgroup+0xf0>
mov    0x2dc3(%rip),%rax
mov    (%rax),%ebx
mov    0x2db2(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1230 <join_cgroup+0xc0>
call   1090 <strerror@plt>
mov    %rax,%r8
jmp    1237 <join_cgroup+0xc7>
lea    0xeb5(%rip),%r8
lea    0xdd2(%rip),%rsi
lea    0xdee(%rip),%rdx
mov    %ebx,%edi
mov    $0x2b,%ecx
call   1070 <fprintf@plt>
mov    $0x1,%r14d
jmp    1288 <join_cgroup+0x118>
lea    0xe8c(%rip),%r8
lea    0xe8e(%rip),%rsi
lea    0xdc5(%rip),%rdx
mov    %r14d,%edi
mov    $0x31,%ecx
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"%s/cgroup.procs\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"(%s:%d: errno: %s) Opening Cgroup\0A\00"
@.str.2 = [185 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/williamfdevine/PrettyLinux/refs/heads/master/samples/bpf/test_current_task_under_cgroup_user.c\00"
@errno = global i64 0
@.str.3 = [5 x i8] c"None\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [35 x i8] c"(%s:%d: errno: %s) Joining Cgroup\0A\00"
define i32 @join_cgroup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%10 = call i32 (...) @getpid()
store i32 %10, i32* %6
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = trunc i64 %13 to i32
%17 = load i8*, i8** %3
%18 = call i32 @snprintf(i8* %15, i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* %15, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = load i64, i64* @errno
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %31
28: ; preds = %23
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
br label %31
31: ; preds = %28, %27
%32 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %27 ], [ %30, %28 ]
%33 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.2, i64 0, i64 0), i32 43, i8* %32)
store i32 1, i32* %2
store i32 1, i32* %9
br label %54
34: ; preds = %1
%35 = load i32, i32* %4
%36 = load i32, i32* %6
%37 = call i64 @dprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i64, i64* @errno
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
br label %47
44: ; preds = %39
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
br label %47
47: ; preds = %44, %43
%48 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %43 ], [ %46, %44 ]
%49 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.2, i64 0, i64 0), i32 49, i8* %48)
store i32 1, i32* %5
br label %50
50: ; preds = %47, %34
%51 = load i32, i32* %4
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %5
store i32 %53, i32* %2
store i32 1, i32* %9
br label %54
54: ; preds = %50, %31
%55 = load i8*, i8** %7
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"%s/cgroup.procs\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"(%s:%d: errno: %s) Opening Cgroup\0A\00"
@.str.2 = [185 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/williamfdevine/PrettyLinux/refs/heads/master/samples/bpf/test_current_task_under_cgroup_user.c\00"
@errno = global i64 0
@.str.3 = [5 x i8] c"None\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [35 x i8] c"(%s:%d: errno: %s) Joining Cgroup\0A\00"
define i32 @join_cgroup(i8* %0) {
%2 = tail call i32 (...) @getpid()
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* %6, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i64, i64* @errno
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i8* @strerror(i64 %13)
br label %17
17: ; preds = %11, %15
%18 = phi i8* [ %16, %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %11 ]
%19 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.2, i64 0, i64 0), i32 43, i8* %18)
br label %35
20: ; preds = %1
%21 = call i64 @dprintf(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %2)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i64, i64* @errno
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i8* @strerror(i64 %25)
br label %29
29: ; preds = %23, %27
%30 = phi i8* [ %28, %27 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %23 ]
%31 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([185 x i8], [185 x i8]* @.str.2, i64 0, i64 0), i32 49, i8* %30)
br label %32
32: ; preds = %29, %20
%33 = phi i32 [ 1, %29 ], [ 0, %20 ]
%34 = call i32 @close(i32 %9)
br label %35
35: ; preds = %32, %17
%36 = phi i32 [ 1, %17 ], [ %33, %32 ]
ret i32 %36
}