#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int change_clocksource(char *clocksource) {
  int fd;
  ssize_t size;
  fd = open("/sys/devices/system/clocksource/clocksource0/current_clocksource",
            O_WRONLY);
  if (fd < 0) {
    return -1;
  }
  size = write(fd, clocksource, strlen(clocksource));
  if (size < 0) {
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<change_clocksource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117a <change_clocksource+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <change_clocksource+0x89>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11ba <change_clocksource+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <change_clocksource+0x89>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_clocksource>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xea9(%rip),%rdi
call   1060 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     118b <change_clocksource+0x4b>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     118b <change_clocksource+0x4b>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"/sys/devices/system/clocksource/clocksource0/current_clocksource\00"
@O_WRONLY = global i32 0
define i32 @change_clocksource(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %23
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i64 @write(i32 %12, i8* %13, i32 %15)
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 -1, i32* %2
br label %23
20: ; preds = %11
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
store i32 0, i32* %2
br label %23
23: ; preds = %20, %19, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [65 x i8] c"/sys/devices/system/clocksource/clocksource0/current_clocksource\00"
@O_WRONLY = global i32 0
define i32 @change_clocksource(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i64 @write(i32 %3, i8* %0, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %5, %1, %9
%12 = phi i32 [ 0, %9 ], [ -1, %1 ], [ -1, %5 ]
ret i32 %12
}