#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 F_OK;
scalar_t__ access(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int test_sysattr(char *attribute, int perms, int threads_in_system) {
  char path[128];
  int i;
  for (i = 0; i < threads_in_system; i++) {
    sprintf(path,
            "/sys/devices/system/cpu/cpu%d"
            "/%s",
            i, attribute);
    if (access(path, F_OK))
      continue;
    if (access(path, perms))
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<test_sysattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11cd <test_sysattr+0xad>
lea    -0xa0(%rbp),%rdi
mov    -0xa4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe9a(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1030 <access@plt>
cmp    $0x0,%rax
je     118f <test_sysattr+0x6f>
jmp    11b9 <test_sysattr+0x99>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <access@plt>
cmp    $0x0,%rax
je     11b4 <test_sysattr+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <test_sysattr+0xb4>
jmp    11b9 <test_sysattr+0x99>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    113f <test_sysattr+0x1f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sysattr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %esi,0xc(%rsp)
mov    $0x1,%eax
test   %edx,%edx
jle    11a1 <test_sysattr+0x81>
mov    %edx,%ebp
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xeb4(%rip),%r13
lea    0x10(%rsp),%r14
mov    0x2e80(%rip),%r15
jmp    1167 <test_sysattr+0x47>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     119c <test_sysattr+0x7c>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %r12,%rcx
call   1040 <sprintf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <access@plt>
test   %rax,%rax
jne    1160 <test_sysattr+0x40>
mov    %r14,%rdi
mov    0xc(%rsp),%esi
call   1030 <access@plt>
test   %rax,%rax
je     1160 <test_sysattr+0x40>
xor    %eax,%eax
jmp    11a1 <test_sysattr+0x81>
mov    $0x1,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"/sys/devices/system/cpu/cpu%d/%s\00"
@F_OK = global i32 0
define i32 @test_sysattr(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %31, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%16 = load i32, i32* %9
%17 = load i8*, i8** %5
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* @F_OK
%21 = call i64 @access(i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %14
br label %31
24: ; preds = %14
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* %6
%27 = call i64 @access(i8* %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %4
br label %35
30: ; preds = %24
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %10
34: ; preds = %10
store i32 1, i32* %4
br label %35
35: ; preds = %34, %29
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [33 x i8] c"/sys/devices/system/cpu/cpu%d/%s\00"
@F_OK = global i32 0
define i32 @test_sysattr(i8* %0, i32 %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %19
7: ; preds = %3, %16
%8 = phi i32 [ %17, %16 ], [ 0, %3 ]
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %0)
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* %5, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call i64 @access(i8* %5, i32 %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13, %7
%17 = add nuw nsw i32 %8, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %7
19: ; preds = %13, %16, %3
%20 = phi i32 [ 1, %3 ], [ 1, %16 ], [ 0, %13 ]
ret i32 %20
}