#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 EINVAL;
int ENOMEM;
int /*<<< orphan*/ isempty(char const *);
int /*<<< orphan*/ path_kill_slashes(char *);
char *strappend(char *, char const *);
char *strdup(char const *);
char *strjoin(char const *, char const *, char const *, char const *, ...);
int join_path(const char *controller, const char *path, const char *suffix,
              char **fs) {
  char *t = NULL;
  if (!isempty(controller)) {
    if (!isempty(path) && !isempty(suffix))
      t = strjoin("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL);
    else if (!isempty(path))
      t = strjoin("/sys/fs/cgroup/", controller, "/", path, NULL);
    else if (!isempty(suffix))
      t = strjoin("/sys/fs/cgroup/", controller, "/", suffix, NULL);
    else
      t = strappend("/sys/fs/cgroup/", controller);
  } else {
    if (!isempty(path) && !isempty(suffix))
      t = strjoin(path, "/", suffix, NULL);
    else if (!isempty(path))
      t = strdup(path);
    else
      return -EINVAL;
  }
  if (!t)
    return -ENOMEM;
  path_kill_slashes(t);
  *fs = t;
  return 0;
}


x86 assembly (clang, -O0):
<join_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    127a <join_path+0x12a>
mov    -0x18(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    11dd <join_path+0x8d>
mov    -0x20(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    11dd <join_path+0x8d>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r9
lea    0xe47(%rip),%rdi
lea    0xe4e(%rip),%r8
xor    %eax,%eax
mov    %r8,%rdx
movq   $0x0,(%rsp)
mov    $0x0,%al
call   1050 <strjoin@plt>
mov    %rax,-0x30(%rbp)
jmp    1275 <join_path+0x125>
mov    -0x18(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    121a <join_path+0xca>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe02(%rip),%rdi
lea    0xe09(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1050 <strjoin@plt>
mov    %rax,-0x30(%rbp)
jmp    1270 <join_path+0x120>
mov    -0x20(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    1257 <join_path+0x107>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xdc5(%rip),%rdi
lea    0xdcc(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1050 <strjoin@plt>
mov    %rax,-0x30(%rbp)
jmp    126b <join_path+0x11b>
mov    -0x10(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1040 <strappend@plt>
mov    %rax,-0x30(%rbp)
jmp    1270 <join_path+0x120>
jmp    1275 <join_path+0x125>
jmp    1302 <join_path+0x1b2>
mov    -0x18(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    12c1 <join_path+0x171>
mov    -0x20(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    12c1 <join_path+0x171>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd61(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1050 <strjoin@plt>
mov    %rax,-0x30(%rbp)
jmp    12fd <join_path+0x1ad>
mov    -0x18(%rbp),%rdi
call   1070 <isempty@plt>
cmp    $0x0,%eax
jne    12e5 <join_path+0x195>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    12f8 <join_path+0x1a8>
xor    %eax,%eax
mov    0x2cea(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    133b <join_path+0x1eb>
jmp    12fd <join_path+0x1ad>
jmp    1302 <join_path+0x1b2>
cmpq   $0x0,-0x30(%rbp)
jne    1320 <join_path+0x1d0>
xor    %eax,%eax
mov    0x2cca(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    133b <join_path+0x1eb>
mov    -0x30(%rbp),%rdi
call   1030 <path_kill_slashes@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
call   1070 <isempty@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <isempty@plt>
test   %ebp,%ebp
je     11a3 <join_path+0x53>
test   %eax,%eax
jne    118b <join_path+0x3b>
mov    %r15,%rdi
call   1070 <isempty@plt>
test   %eax,%eax
je     11fc <join_path+0xac>
mov    %rbx,%rdi
call   1070 <isempty@plt>
test   %eax,%eax
je     11dc <join_path+0x8c>
mov    0x2e3a(%rip),%rcx
jmp    1274 <join_path+0x124>
test   %eax,%eax
jne    11b3 <join_path+0x63>
mov    %r15,%rdi
call   1070 <isempty@plt>
test   %eax,%eax
je     122d <join_path+0xdd>
mov    %rbx,%rdi
call   1070 <isempty@plt>
test   %eax,%eax
je     11e6 <join_path+0x96>
mov    %r15,%rdi
call   1070 <isempty@plt>
lea    0xe32(%rip),%rdi
test   %eax,%eax
je     1214 <join_path+0xc4>
mov    %r12,%rsi
call   1040 <strappend@plt>
jmp    1256 <join_path+0x106>
mov    %rbx,%rdi
call   1060 <strdup@plt>
jmp    1256 <join_path+0x106>
lea    0xe13(%rip),%rdi
lea    0xe1a(%rip),%rdx
mov    %r12,%rsi
mov    %rbx,%rcx
jmp    1221 <join_path+0xd1>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1050 <strjoin@plt>
jmp    1256 <join_path+0x106>
lea    0xdf3(%rip),%rdx
mov    %r12,%rsi
mov    %r15,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <strjoin@plt>
jmp    1256 <join_path+0x106>
movq   $0x0,(%rsp)
lea    0xdc4(%rip),%rdi
lea    0xdcb(%rip),%rdx
mov    %r12,%rsi
mov    %rbx,%rcx
mov    %rdx,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1050 <strjoin@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126d <join_path+0x11d>
mov    %rbx,%rdi
call   1030 <path_kill_slashes@plt>
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    1278 <join_path+0x128>
mov    0x2d6c(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/sys/fs/cgroup/\00"
@.str.1 = [2 x i8] c"/\00"
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @join_path(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*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
store i8* null, i8** %10
%11 = load i8*, i8** %6
%12 = call i32 @isempty(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %49, label %14
14: ; preds = %4
%15 = load i8*, i8** %7
%16 = call i32 @isempty(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %14
%19 = load i8*, i8** %8
%20 = call i32 @isempty(i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* null)
store i8* %26, i8** %10
br label %48
27: ; preds = %18, %14
%28 = load i8*, i8** %7
%29 = call i32 @isempty(i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* null)
store i8* %34, i8** %10
br label %47
35: ; preds = %27
%36 = load i8*, i8** %8
%37 = call i32 @isempty(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i8*, i8** %8
%42 = call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* null)
store i8* %42, i8** %10
br label %46
43: ; preds = %35
%44 = load i8*, i8** %6
%45 = call i8* @strappend(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %44)
store i8* %45, i8** %10
br label %46
46: ; preds = %43, %39
br label %47
47: ; preds = %46, %31
br label %48
48: ; preds = %47, %22
br label %73
49: ; preds = %4
%50 = load i8*, i8** %7
%51 = call i32 @isempty(i8* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %61, label %53
53: ; preds = %49
%54 = load i8*, i8** %8
%55 = call i32 @isempty(i8* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i8*, i8** %7
%59 = load i8*, i8** %8
%60 = call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %59, i8* null)
store i8* %60, i8** %10
br label %72
61: ; preds = %53, %49
%62 = load i8*, i8** %7
%63 = call i32 @isempty(i8* %62)
%64 = icmp ne i32 %63, 0
br i1 %64, label %68, label %65
65: ; preds = %61
%66 = load i8*, i8** %7
%67 = call i8* @strdup(i8* %66)
store i8* %67, i8** %10
br label %71
68: ; preds = %61
%69 = load i32, i32* @EINVAL
%70 = sub nsw i32 0, %69
store i32 %70, i32* %5
br label %84
71: ; preds = %65
br label %72
72: ; preds = %71, %57
br label %73
73: ; preds = %72, %48
%74 = load i8*, i8** %10
%75 = icmp ne i8* %74, null
br i1 %75, label %79, label %76
76: ; preds = %73
%77 = load i32, i32* @ENOMEM
%78 = sub nsw i32 0, %77
store i32 %78, i32* %5
br label %84
79: ; preds = %73
%80 = load i8*, i8** %10
%81 = call i32 @path_kill_slashes(i8* %80)
%82 = load i8*, i8** %10
%83 = load i8**, i8*** %9
store i8* %82, i8** %83
store i32 0, i32* %5
br label %84
84: ; preds = %79, %76, %68
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
@.str = [16 x i8] c"/sys/fs/cgroup/\00"
@.str.1 = [2 x i8] c"/\00"
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @join_path(i8* %0, i8* %1, i8* %2, i8** nocapture writeonly %3) {
%5 = tail call i32 @isempty(i8* %0)
%6 = icmp eq i32 %5, 0
%7 = tail call i32 @isempty(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %6, label %9, label %27
9: ; preds = %4
br i1 %8, label %10, label %15
10: ; preds = %9
%11 = tail call i32 @isempty(i8* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* null)
br label %41
15: ; preds = %10, %9
%16 = tail call i32 @isempty(i8* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* null)
br label %41
20: ; preds = %15
%21 = tail call i32 @isempty(i8* %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* null)
br label %41
25: ; preds = %20
%26 = tail call i8* @strappend(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
27: ; preds = %4
br i1 %8, label %28, label %33
28: ; preds = %27
%29 = tail call i32 @isempty(i8* %2)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i8* (i8*, i8*, i8*, i8*, ...) @strjoin(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* null)
br label %41
33: ; preds = %28, %27
%34 = tail call i32 @isempty(i8* %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i8* @strdup(i8* %1)
br label %41
38: ; preds = %33
%39 = load i32, i32* @EINVAL
%40 = sub nsw i32 0, %39
br label %49
41: ; preds = %31, %36, %13, %23, %25, %18
%42 = phi i8* [ %37, %36 ], [ %32, %31 ], [ %26, %25 ], [ %24, %23 ], [ %19, %18 ], [ %14, %13 ]
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* @ENOMEM
%46 = sub nsw i32 0, %45
br label %49
47: ; preds = %41
%48 = tail call i32 @path_kill_slashes(i8* %42)
store i8* %42, i8** %3
br label %49
49: ; preds = %47, %44, %38
%50 = phi i32 [ %40, %38 ], [ 0, %47 ], [ %46, %44 ]
ret i32 %50
}