#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ *opendir(char const *const);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int sscanf(char *, char *, char *, int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  DIR *d;
  struct dirent *de;
  const char *const path = "/sys/devices/system/cpu/";
  char filename[255];
  int number;
  int sscanf_ret;
  d = opendir(path);
  while ((de = readdir(d))) {
    printf(de->d_name);
    sscanf_ret = sscanf(de->d_name, "%s%d", filename, number);
    if (sscanf_ret < 2) {
      printf("error\n");
    }
    if (strcmp(filename, "cpu") == 0) {
      printf("%s%s\n", path, de->d_name);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1228 <main+0xd8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x130(%rbp),%rdx
mov    -0x134(%rbp),%ecx
lea    0xe55(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0x2,-0x138(%rbp)
jge    11ea <main+0x9a>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1223 <main+0xd3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe14(%rip),%rdi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1184 <main+0x34>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe88(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     121b <main+0xbb>
mov    %rax,%rbp
lea    0xe7e(%rip),%r14
mov    %rsp,%rbx
lea    0xe83(%rip),%r12
lea    0xe72(%rip),%r13
jmp    11d0 <main+0x70>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0xa0>
mov    %r15,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     121b <main+0xbb>
mov    0x0(%rbp),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jg     11b0 <main+0x50>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x50>
nopl   0x0(%rax)
mov    0x0(%rbp),%rdx
lea    0xe17(%rip),%rdi
lea    0xdee(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <main+0x60>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [25 x i8] c"/sys/devices/system/cpu/\00"
@.str.1 = [5 x i8] c"%s%d\00"
@.str.2 = [7 x i8] c"error\0A\00"
@.str.3 = [4 x i8] c"cpu\00"
@.str.4 = [6 x i8] c"%s%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca [255 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0))
store i32* %12, i32** %6
br label %13
13: ; preds = %41, %2
%14 = load i32*, i32** %6
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %7
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %7
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* %20)
%22 = load %struct.dirent*, %struct.dirent** %7
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%26 = load i32, i32* %10
%27 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %17
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load %struct.dirent*, %struct.dirent** %7
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i8* %39)
br label %41
41: ; preds = %36, %32
br label %13
42: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [25 x i8] c"/sys/devices/system/cpu/\00"
@.str.1 = [5 x i8] c"%s%d\00"
@.str.3 = [4 x i8] c"cpu\00"
@.str.4 = [6 x i8] c"%s%s\0A\00"
@str = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call %struct.dirent* @readdir(i32* %5)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %27, label %8
8: ; preds = %2, %24
%9 = phi %struct.dirent* [ %25, %24 ], [ %6, %2 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %11)
%13 = load i8*, i8** %10
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 undef)
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
%19 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %10
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %18
%25 = call %struct.dirent* @readdir(i32* %5)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %8
27: ; preds = %24, %2
ret i32 0
}