#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*/ path;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FILENAME_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            char const *, ...);
int cgroupCreateInherit(const char *cgid, const char *prefix, const char *type,
                        const char *key) {
  char path[FILENAME_MAX + 1];
  char line[65];
  snprintf(path, sizeof(path), "%s/%s/%s", prefix, type, key);
  FILE *fp = fopen(path, "re");
  if (fp == NULL || fscanf(fp, "%64[^\n]", line) != 1) {
    if (fp != NULL)
      fclose(fp);
    return -1;
  }
  fclose(fp);
  snprintf(path, sizeof(path), "%s/%s/%s/%s", prefix, type, cgid, key);
  fp = fopen(path, "we");
  if (fp == NULL || fprintf(fp, "%s", line) <= 0) {
    if (fp != NULL)
      fclose(fp);
    return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<cgroupCreateInherit>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0xa0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x98(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xe55(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x98(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1208 <cgroupCreateInherit+0xb8>
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe09(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     1238 <cgroupCreateInherit+0xe8>
cmpq   $0x0,-0x88(%rbp)
je     1222 <cgroupCreateInherit+0xd2>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1314 <cgroupCreateInherit+0x1c4>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x28(%rbp),%rax
lea    0xda0(%rip),%rdx
sub    $0x10,%rsp
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x98(%rbp),%rdi
add    $0x10,%rsp
lea    0xd8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     12c7 <cgroupCreateInherit+0x177>
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd5c(%rip),%rsi
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jg     12f7 <cgroupCreateInherit+0x1a7>
cmpq   $0x0,-0x88(%rbp)
je     12e1 <cgroupCreateInherit+0x191>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1314 <cgroupCreateInherit+0x1c4>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgroupCreateInherit>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%rcx
mov    %rdi,-0x40(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%r14d
add    $0x1,%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe7a(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rcx,-0x38(%rbp)
mov    %rbx,%r8
mov    %r13,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe4e(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    $0xffffffff,%eax
test   %r15,%r15
je     126d <cgroupCreateInherit+0x11d>
mov    %r13,-0x30(%rbp)
lea    0xe2d(%rip),%rsi
lea    -0x90(%rbp),%rdx
mov    %r15,%rdi
call   1050 <fscanf@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%r13d
jne    1268 <cgroupCreateInherit+0x118>
sub    $0x8,%rsp
lea    0xe0a(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    -0x38(%rbp),%rcx
mov    %rbx,%r8
mov    -0x40(%rbp),%r9
xor    %eax,%eax
push   -0x30(%rbp)
call   1040 <snprintf@plt>
add    $0x10,%rsp
lea    0xdf0(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
mov    $0xffffffff,%eax
je     126d <cgroupCreateInherit+0x11d>
lea    0xdd1(%rip),%rsi
lea    -0x90(%rbp),%rdx
mov    %r14,%rdi
call   1060 <fprintf@plt>
xor    %ebx,%ebx
test   %rax,%rax
setle  %bl
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
neg    %eax
jmp    126d <cgroupCreateInherit+0x11d>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [9 x i8] c"%s/%s/%s\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [8 x i8] c"%64[^\0A]\00"
@.str.3 = [12 x i8] c"%s/%s/%s/%s\00"
@.str.4 = [3 x i8] c"we\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @cgroupCreateInherit(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca [65 x i8]
%13 = alloca i32*
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%15 = load i32, i32* @FILENAME_MAX
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %10
%19 = alloca i8, i64 %17
store i64 %17, i64* %11
%20 = trunc i64 %17 to i32
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = load i8*, i8** %9
%24 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %19, i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
%25 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %13
%26 = load i32*, i32** %13
%27 = icmp eq i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %4
%29 = load i32*, i32** %13
%30 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%31 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %40
33: ; preds = %28, %4
%34 = load i32*, i32** %13
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %13
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %33
store i32 -1, i32* %5
store i32 1, i32* %14
br label %67
40: ; preds = %28
%41 = load i32*, i32** %13
%42 = call i32 @fclose(i32* %41)
%43 = trunc i64 %17 to i32
%44 = load i8*, i8** %7
%45 = load i8*, i8** %8
%46 = load i8*, i8** %6
%47 = load i8*, i8** %9
%48 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %19, i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %44, i8* %45, i8* %46, i8* %47)
%49 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %49, i32** %13
%50 = load i32*, i32** %13
%51 = icmp eq i32* %50, null
br i1 %51, label %57, label %52
52: ; preds = %40
%53 = load i32*, i32** %13
%54 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%55 = call i64 @fprintf(i32* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = icmp sle i64 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %52, %40
%58 = load i32*, i32** %13
%59 = icmp ne i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32*, i32** %13
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %60, %57
store i32 -1, i32* %5
store i32 1, i32* %14
br label %67
64: ; preds = %52
%65 = load i32*, i32** %13
%66 = call i32 @fclose(i32* %65)
store i32 0, i32* %5
store i32 1, i32* %14
br label %67
67: ; preds = %64, %63, %39
%68 = load i8*, i8** %10
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [9 x i8] c"%s/%s/%s\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [8 x i8] c"%64[^\0A]\00"
@.str.3 = [12 x i8] c"%s/%s/%s/%s\00"
@.str.4 = [3 x i8] c"we\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @cgroupCreateInherit(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [65 x i8]
%6 = load i32, i32* @FILENAME_MAX
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = getelementptr inbounds [65 x i8], [65 x i8]* %5, i64 0, i64 0
%11 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %9, i32 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i8* %3)
%12 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %4
%15 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%16 = icmp eq i32 %15, 1
%17 = call i32 @fclose(i32* %12)
br i1 %16, label %18, label %27
18: ; preds = %14
%19 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) @snprintf(i8* %9, i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2, i8* %0, i8* %3)
%20 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = call i64 @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%24 = icmp slt i64 %23, 1
%25 = call i32 @fclose(i32* %20)
%26 = sext i1 %24 to i32
br label %27
27: ; preds = %22, %14, %18, %4
%28 = phi i32 [ -1, %4 ], [ -1, %18 ], [ -1, %14 ], [ %26, %22 ]
ret i32 %28
}