#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char const *const, char *);
char *util_path_sysfs(char *, char const *const);
void test_util_path_sysfs(void) {
  const char *const subsys_vec[] = {"cpu", "memory"};
  char *path;
  int i;
  for (i = 0; i < 2; i++) {
    path = util_path_sysfs("devices/system/%s", subsys_vec[i]);
    printf("Path for %6s: \"%s\"\n", subsys_vec[i], path);
    free(path);
  }
}


x86 assembly (clang, -O0):
<test_util_path_sysfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2cd1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2cce(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    11a8 <test_util_path_sysfs+0x78>
movslq -0x1c(%rbp),%rax
mov    -0x10(%rbp,%rax,8),%rsi
lea    0xe9c(%rip),%rdi
call   1050 <util_path_sysfs@plt>
mov    %rax,-0x18(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x10(%rbp,%rax,8),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <test_util_path_sysfs+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_util_path_sysfs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xecc(%rip),%r14
lea    0xeba(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <util_path_sysfs@plt>
mov    %rax,%rbx
lea    0xec2(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe8c(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <util_path_sysfs@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"cpu\00"
@.str.1 = [7 x i8] c"memory\00"
@__const.test_util_path_sysfs.subsys_vec = [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [18 x i8] c"devices/system/%s\00"
@.str.3 = [20 x i8] c"Path for %6s: \22%s\22\0A\00"
define void @test_util_path_sysfs() {
%1 = alloca [2 x i8*]
%2 = alloca i8*
%3 = alloca i32
%4 = bitcast [2 x i8*]* %1 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %22, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 %10
%12 = load i8*, i8** %11
%13 = call i8* @util_path_sysfs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %12)
store i8* %13, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %8
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %5
25: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"cpu\00"
@.str.1 = [7 x i8] c"memory\00"
@.str.2 = [18 x i8] c"devices/system/%s\00"
@.str.3 = [20 x i8] c"Path for %6s: \22%s\22\0A\00"
define void @test_util_path_sysfs() {
%1 = tail call i8* @util_path_sysfs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i32 @free(i8* %1)
%4 = tail call i8* @util_path_sysfs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = tail call i32 @free(i8* %4)
ret void
}