#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
scalar_t__ sysfs(int, int, char *);
int sysfs1(int);
main() {
  int i, tot;
  char buf[100];
  tot = sysfs1(3);
  if (tot == -1) {
    perror("sysfs(3)");
    exit(1);
  }
  for (i = 0; i < tot; i++) {
    if (sysfs(2, i, buf)) {
      perror("sysfs(2)");
      exit(1);
    }
    printf("%2d: %s\n", i, buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
call   1050 <sysfs1@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    118c <main+0x3c>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f1 <main+0xa1>
mov    -0x8(%rbp),%esi
lea    -0x70(%rbp),%rdx
mov    $0x2,%edi
call   1040 <sysfs@plt>
cmp    $0x0,%rax
je     11d0 <main+0x80>
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%esi
lea    -0x70(%rbp),%rdx
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1193 <main+0x43>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    $0x3,%edi
call   1050 <sysfs1@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x7c>
mov    %eax,%r14d
test   %eax,%eax
jle    11a9 <main+0x59>
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xe96(%rip),%r15
nopl   0x0(%rax)
mov    $0x2,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <sysfs@plt>
test   %rax,%rax
jne    11b6 <main+0x66>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1180 <main+0x30>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe2d(%rip),%rdi
jmp    11bd <main+0x6d>

LLVM IR (-O0):
@.str = [9 x i8] c"sysfs(3)\00"
@.str.1 = [9 x i8] c"sysfs(2)\00"
@.str.2 = [9 x i8] c"%2d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i32 @sysfs1(i32 3)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
store i32 0, i32* %2
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i32, i32* %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i64 @sysfs(i32 2, i32 %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32, i32* %2
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26)
br label %28
28: ; preds = %24
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %12
31: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"sysfs(3)\00"
@.str.1 = [9 x i8] c"sysfs(2)\00"
@.str.2 = [9 x i8] c"%2d: %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @sysfs1(i32 3)
%4 = icmp eq i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = icmp sgt i32 %3, 0
br i1 %6, label %10, label %21
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %5, %17
%11 = phi i32 [ %19, %17 ], [ 0, %5 ]
%12 = call i64 @sysfs(i32 2, i32 %11, i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %2)
%19 = add nuw nsw i32 %11, 1
%20 = icmp eq i32 %19, %3
br i1 %20, label %21, label %10
21: ; preds = %17, %5
ret i32 0
}