#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 < 30; 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   $0x1e,-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,%r15
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,%rbp
mov    %ebx,%edi
call   1040 <close@plt>
movb   $0x0,(%r15)
movb   $0x0,0x1e(%r15)
movb   $0x0,0x3c(%r15)
movb   $0x0,0x5a(%r15)
movb   $0x0,0x78(%r15)
movb   $0x0,0x96(%r15)
movb   $0x0,0xb4(%r15)
movb   $0x0,0xd2(%r15)
movb   $0x0,0xf0(%r15)
movb   $0x0,0x10e(%r15)
movb   $0x0,0x12c(%r15)
movb   $0x0,0x14a(%r15)
movb   $0x0,0x168(%r15)
movb   $0x0,0x186(%r15)
movb   $0x0,0x1a4(%r15)
movb   $0x0,0x1c2(%r15)
movb   $0x0,0x1e0(%r15)
movb   $0x0,0x1fe(%r15)
movb   $0x0,0x21c(%r15)
movb   $0x0,0x23a(%r15)
movb   $0x0,0x258(%r15)
movb   $0x0,0x276(%r15)
movb   $0x0,0x294(%r15)
movb   $0x0,0x2b2(%r15)
movb   $0x0,0x2d0(%r15)
movb   $0x0,0x2ee(%r15)
movb   $0x0,0x30c(%r15)
movb   $0x0,0x32a(%r15)
movb   $0x0,0x348(%r15)
movb   $0x0,0x366(%r15)
mov    %rbp,0x8(%rsp)
test   %rbp,%rbp
je     12eb <get_clocksources+0x1ab>
mov    $0x1,%eax
sub    %r14,%rax
mov    %rax,(%rsp)
xor    %ebx,%ebx
movabs $0x100000401,%rbp
nopl   0x0(%rax,%rax,1)
lea    0x1(%r14),%r12
mov    (%rsp),%rax
lea    (%rax,%r14,1),%r13
jmp    12a8 <get_clocksources+0x168>
xchg   %ax,%ax
add    $0x1,%r12
add    $0x1,%r13
movzbl -0x1(%r12),%eax
cmp    $0x20,%rax
ja     12a0 <get_clocksources+0x160>
bt     %rax,%rbp
jae    12a0 <get_clocksources+0x160>
movb   $0x0,-0x1(%r12)
mov    %rbx,%rdi
shl    $0x5,%rdi
sub    %rbx,%rdi
sub    %rbx,%rdi
add    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
mov    %r12,%r14
cmp    0x8(%rsp),%r13
jb     1290 <get_clocksources+0x150>
add    $0xffffffff,%ebx
jmp    12f0 <get_clocksources+0x1b0>
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, 30
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 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 10, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 11, i64 0
store i8 0, i8* %19
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 12, i64 0
store i8 0, i8* %20
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 13, i64 0
store i8 0, i8* %21
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 14, i64 0
store i8 0, i8* %22
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 15, i64 0
store i8 0, i8* %23
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 16, i64 0
store i8 0, i8* %24
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 17, i64 0
store i8 0, i8* %25
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 18, i64 0
store i8 0, i8* %26
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 19, i64 0
store i8 0, i8* %27
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 20, i64 0
store i8 0, i8* %28
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 21, i64 0
store i8 0, i8* %29
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 22, i64 0
store i8 0, i8* %30
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 23, i64 0
store i8 0, i8* %31
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 24, i64 0
store i8 0, i8* %32
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 25, i64 0
store i8 0, i8* %33
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 26, i64 0
store i8 0, i8* %34
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 27, i64 0
store i8 0, i8* %35
%36 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 28, i64 0
store i8 0, i8* %36
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 29, i64 0
store i8 0, i8* %37
%38 = ptrtoint [512 x i8]* %2 to i64
%39 = icmp eq i64 %6, 0
br i1 %39, label %59, label %40
40: ; preds = %1, %48
%41 = phi i64 [ %52, %48 ], [ 0, %1 ]
%42 = phi i8* [ %51, %48 ], [ %3, %1 ]
br label %43
43: ; preds = %40, %46
%44 = phi i8* [ %47, %46 ], [ %42, %40 ]
%45 = load i8, i8* %44
switch i8 %45, label %46 [
i8 32, label %48
i8 10, label %48
i8 0, label %48
]
46: ; preds = %43
%47 = getelementptr inbounds i8, i8* %44, i64 1
br label %43
48: ; preds = %43, %43, %43
store i8 0, i8* %44
%49 = getelementptr inbounds [30 x i8], [30 x i8]* %0, i64 %41, i64 0
%50 = call i32 @strcpy(i8* %49, i8* %42)
%51 = getelementptr inbounds i8, i8* %44, i64 1
%52 = add nuw i64 %41, 1
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %53, %38
%55 = icmp ult i64 %54, %6
br i1 %55, label %40, label %56
56: ; preds = %48
%57 = trunc i64 %52 to i32
%58 = add i32 %57, -1
br label %59
59: ; preds = %56, %1
%60 = phi i32 [ -1, %1 ], [ %58, %56 ]
ret i32 %60
}