#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
size_t read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int get_clocksources(char list[][30]) {
  int fd, i;
  size_t size;
  char buf[512];
  char *head, *tmp;
  fd =
      open("/sys/devices/system/clocksource/clocksource0/available_clocksource",
           O_RDONLY);
  size = read(fd, buf, 512);
  close(fd);
  for (i = 0; i < 10; i++)
    list[i][0] = '\0';
  head = buf;
  i = 0;
  while (head - buf < size) {
    for (tmp = head; *tmp != ' '; tmp++) {
      if (*tmp == '\n')
        break;
      if (*tmp == '\0')
        break;
    }
    *tmp = '\0';
    strcpy(list[i], head);
    head = tmp + 1;
    i++;
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<get_clocksources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11b8 <get_clocksources+0x78>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   $0x1e,%rcx,%rcx
add    %rcx,%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <get_clocksources+0x4e>
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x228(%rbp),%rax
lea    -0x220(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x18(%rbp),%rax
jae    129a <get_clocksources+0x15a>
mov    -0x228(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1255 <get_clocksources+0x115>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1221 <get_clocksources+0xe1>
jmp    1255 <get_clocksources+0x115>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1239 <get_clocksources+0xf9>
jmp    1255 <get_clocksources+0x115>
jmp    123e <get_clocksources+0xfe>
mov    -0x230(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x230(%rbp)
jmp    11f6 <get_clocksources+0xb6>
mov    -0x230(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
imul   $0x1e,%rax,%rax
add    %rax,%rdi
mov    -0x228(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x230(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cd <get_clocksources+0x8d>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_clocksources>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdi,%rbp
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1040 <close@plt>
movb   $0x0,0x0(%rbp)
movb   $0x0,0x1e(%rbp)
movb   $0x0,0x3c(%rbp)
movb   $0x0,0x5a(%rbp)
movb   $0x0,0x78(%rbp)
movb   $0x0,0x96(%rbp)
movb   $0x0,0xb4(%rbp)
movb   $0x0,0xd2(%rbp)
movb   $0x0,0xf0(%rbp)
mov    %rbp,0x8(%rsp)
movb   $0x0,0x10e(%rbp)
mov    %r15,(%rsp)
test   %r15,%r15
je     124c <get_clocksources+0x10c>
mov    $0x1,%r13d
sub    %r14,%r13
xor    %ebx,%ebx
movabs $0x100000401,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r14),%r12
lea    (%r14,%r13,1),%r15
jmp    1208 <get_clocksources+0xc8>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x1,%r15
movzbl -0x1(%r12),%eax
cmp    $0x20,%rax
ja     1200 <get_clocksources+0xc0>
bt     %rax,%rbp
jae    1200 <get_clocksources+0xc0>
movb   $0x0,-0x1(%r12)
mov    %rbx,%rdi
shl    $0x5,%rdi
sub    %rbx,%rdi
sub    %rbx,%rdi
add    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
mov    %r12,%r14
cmp    (%rsp),%r15
jb     11f0 <get_clocksources+0xb0>
add    $0xffffffff,%ebx
jmp    1251 <get_clocksources+0x111>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"/sys/devices/system/clocksource/clocksource0/available_clocksource\00"
@O_RDONLY = global i32 0
define i32 @get_clocksources([30 x i8]* %0) {
%2 = alloca [30 x i8]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
store [30 x i8]* %0, [30 x i8]** %2
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 512)
store i64 %13, i64* %5
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
store i32 0, i32* %4
br label %16
16: ; preds = %25, %1
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load [30 x i8]*, [30 x i8]** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %20, i64 %22
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %23, i64 0, i64 0
store i8 0, i8* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %16
28: ; preds = %16
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
store i8* %29, i8** %7
store i32 0, i32* %4
br label %30
30: ; preds = %61, %28
%31 = load i8*, i8** %7
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = load i64, i64* %5
%37 = icmp ult i64 %35, %36
br i1 %37, label %38, label %74
38: ; preds = %30
%39 = load i8*, i8** %7
store i8* %39, i8** %8
br label %40
40: ; preds = %58, %38
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 32
br i1 %44, label %45, label %61
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 10
br i1 %49, label %50, label %51
50: ; preds = %45
br label %61
51: ; preds = %45
%52 = load i8*, i8** %8
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %51
br label %61
57: ; preds = %51
br label %58
58: ; preds = %57
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %8
br label %40
61: ; preds = %56, %50, %40
%62 = load i8*, i8** %8
store i8 0, i8* %62
%63 = load [30 x i8]*, [30 x i8]** %2
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [30 x i8], [30 x i8]* %63, i64 %65
%67 = getelementptr inbounds [30 x i8], [30 x i8]* %66, i64 0, i64 0
%68 = load i8*, i8** %7
%69 = call i32 @strcpy(i8* %67, i8* %68)
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8* %71, i8** %7
%72 = load i32, i32* %4
%73 = add nsw i32 %72, 1
store i32 %73, i32* %4
br label %30
74: ; preds = %30
%75 = load i32, i32* %4
%76 = sub nsw i32 %75, 1
ret i32 %76
}

LLVM IR (-O2):
@.str = [67 x i8] c"/sys/devices/system/clocksource/clocksource0/available_clocksource\00"
@O_RDONLY = global i32 0
define i32 @get_clocksources([30 x i8]* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i64 @read(i32 %5, i8* %3, i32 512)
%7 = tail call i32 @close(i32 %5)
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 0, i64 0
store i8 0, i8* %8
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 1, i64 0
store i8 0, i8* %9
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 2, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 3, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 4, i64 0
store i8 0, i8* %12
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 5, i64 0
store i8 0, i8* %13
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 6, i64 0
store i8 0, i8* %14
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 7, i64 0
store i8 0, i8* %15
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 8, i64 0
store i8 0, i8* %16
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 9, i64 0
store i8 0, i8* %17
%18 = ptrtoint [512 x i8]* %2 to i64
%19 = icmp eq i64 %6, 0
br i1 %19, label %39, label %20
20: ; preds = %1, %28
%21 = phi i64 [ %32, %28 ], [ 0, %1 ]
%22 = phi i8* [ %31, %28 ], [ %3, %1 ]
br label %23
23: ; preds = %20, %26
%24 = phi i8* [ %27, %26 ], [ %22, %20 ]
%25 = load i8, i8* %24
switch i8 %25, label %26 [
i8 32, label %28
i8 10, label %28
i8 0, label %28
]
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
28: ; preds = %23, %23, %23
store i8 0, i8* %24
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 %21, i64 0
%30 = call i32 @strcpy(i8* %29, i8* %22)
%31 = getelementptr inbounds i8, i8* %24, i64 1
%32 = add nuw i64 %21, 1
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %33, %18
%35 = icmp ult i64 %34, %6
br i1 %35, label %20, label %36
36: ; preds = %28
%37 = trunc i64 %32 to i32
%38 = add i32 %37, -1
br label %39
39: ; preds = %36, %1
%40 = phi i32 [ -1, %1 ], [ %38, %36 ]
ret i32 %40
}