#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*/ snprintf(char *, unsigned int const, char *, ...);
unsigned int const strlen(char *);
int /*<<< orphan*/ strncat(char *, char const *, unsigned int const);
void resctrl_mon_group_path(const unsigned class_id, const char *resctrl_group,
                            const char *file, char *buf,
                            const unsigned buf_size) {
  ;
  if (resctrl_group == NULL) {
    if (class_id == 0)
      snprintf(buf, buf_size, "/sys/fs/resctrl");
    else
      snprintf(buf, buf_size,
               "/sys/fs/resctrl"
               "/COS%u",
               class_id);
  } else if (class_id == 0)
    snprintf(buf, buf_size,
             "/sys/fs/resctrl"
             "/mon_groups/%s",
             resctrl_group);
  else
    snprintf(buf, buf_size,
             "/sys/fs/resctrl"
             "/COS%u/mon_groups/%s",
             class_id, resctrl_group);
  if (file != NULL)
    strncat(buf, file, buf_size - strlen(buf));
}


x86 assembly (clang, -O0):
<resctrl_mon_group_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <resctrl_mon_group_path+0x67>
cmpl   $0x0,-0x4(%rbp)
jne    117a <resctrl_mon_group_path+0x4a>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1192 <resctrl_mon_group_path+0x62>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x4(%rbp),%ecx
lea    0xe85(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11e0 <resctrl_mon_group_path+0xb0>
cmpl   $0x0,-0x4(%rbp)
jne    11bf <resctrl_mon_group_path+0x8f>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xe73(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11db <resctrl_mon_group_path+0xab>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe70(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11e0 <resctrl_mon_group_path+0xb0>
cmpq   $0x0,-0x18(%rbp)
je     121c <resctrl_mon_group_path+0xec>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    %eax,%edx
call   1050 <strncat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resctrl_mon_group_path>:
push   %r15
push   %r14
push   %rbx
mov    %r8d,%ebx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %edi,%ecx
test   %rsi,%rsi
je     1166 <resctrl_mon_group_path+0x36>
mov    %rsi,%r8
test   %ecx,%ecx
je     1184 <resctrl_mon_group_path+0x54>
lea    0xef1(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %r14,%r14
jne    119f <resctrl_mon_group_path+0x6f>
jmp    11d3 <resctrl_mon_group_path+0xa3>
test   %ecx,%ecx
je     11bb <resctrl_mon_group_path+0x8b>
lea    0xe9f(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %r14,%r14
jne    119f <resctrl_mon_group_path+0x6f>
jmp    11d3 <resctrl_mon_group_path+0xa3>
lea    0xe9b(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r8,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %r14,%r14
je     11d3 <resctrl_mon_group_path+0xa3>
mov    %r15,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <strncat@plt>
lea    0xe3e(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %r14,%r14
jne    119f <resctrl_mon_group_path+0x6f>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/sys/fs/resctrl\00"
@.str.1 = [22 x i8] c"/sys/fs/resctrl/COS%u\00"
@.str.2 = [30 x i8] c"/sys/fs/resctrl/mon_groups/%s\00"
@.str.3 = [36 x i8] c"/sys/fs/resctrl/COS%u/mon_groups/%s\00"
define void @resctrl_mon_group_path(i32 %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %26
13: ; preds = %5
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %9
%18 = load i32, i32* %10
%19 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %25
20: ; preds = %13
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %20, %16
br label %41
26: ; preds = %5
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %9
%31 = load i32, i32* %10
%32 = load i8*, i8** %7
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %40
34: ; preds = %26
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = load i32, i32* %6
%38 = load i8*, i8** %7
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %35, i32 %36, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %37, i8* %38)
br label %40
40: ; preds = %34, %29
br label %41
41: ; preds = %40, %25
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %52
44: ; preds = %41
%45 = load i8*, i8** %9
%46 = load i8*, i8** %8
%47 = load i32, i32* %10
%48 = load i8*, i8** %9
%49 = call i32 @strlen(i8* %48)
%50 = sub i32 %47, %49
%51 = call i32 @strncat(i8* %45, i8* %46, i32 %50)
br label %52
52: ; preds = %44, %41
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/sys/fs/resctrl\00"
@.str.1 = [22 x i8] c"/sys/fs/resctrl/COS%u\00"
@.str.2 = [30 x i8] c"/sys/fs/resctrl/mon_groups/%s\00"
@.str.3 = [36 x i8] c"/sys/fs/resctrl/COS%u/mon_groups/%s\00"
define void @resctrl_mon_group_path(i32 %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = icmp eq i8* %1, null
%7 = icmp eq i32 %0, 0
br i1 %6, label %8, label %13
8: ; preds = %5
br i1 %7, label %9, label %11
9: ; preds = %8
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %8
%12 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %18
13: ; preds = %5
br i1 %7, label %14, label %16
14: ; preds = %13
%15 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %18
16: ; preds = %13
%17 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %1)
br label %18
18: ; preds = %14, %16, %9, %11
%19 = icmp eq i8* %2, null
br i1 %19, label %24, label %20
20: ; preds = %18
%21 = tail call i32 @strlen(i8* %3)
%22 = sub i32 %4, %21
%23 = tail call i32 @strncat(i8* %3, i8* %2, i32 %22)
br label %24
24: ; preds = %20, %18
ret void
}