#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void set_default_dscr(unsigned long val) {
  int fd = -1, ret;
  char buf[16];
  if (fd == -1) {
    fd = open("/sys/devices/system/cpu/dscr_default", O_RDWR);
    if (fd == -1) {
      perror("open() failed");
      exit(1);
    }
  }
  sprintf(buf, "%lx\n", val);
  ret = write(fd, buf, strlen(buf));
  if (ret == -1) {
    perror("write() failed");
    exit(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<set_default_dscr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ca <set_default_dscr+0x5a>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c5 <set_default_dscr+0x55>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11ca <set_default_dscr+0x5a>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1226 <set_default_dscr+0xb6>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_default_dscr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d7 <set_default_dscr+0x67>
mov    %eax,%ebx
lea    0xe94(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11e0 <set_default_dscr+0x70>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe47(%rip),%rdi
jmp    11e7 <set_default_dscr+0x77>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"/sys/devices/system/cpu/dscr_default\00"
@O_RDWR = global i32 0
@.str.1 = [14 x i8] c"open() failed\00"
@.str.2 = [5 x i8] c"%lx\0A\00"
@.str.3 = [15 x i8] c"write() failed\00"
define void @set_default_dscr(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
store i64 %0, i64* %2
store i32 -1, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
br label %17
17: ; preds = %16, %1
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%19 = load i64, i64* %2
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = load i32, i32* %3
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i32, i32* %3
%33 = call i32 @close(i32 %32)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"/sys/devices/system/cpu/dscr_default\00"
@O_RDWR = global i32 0
@.str.1 = [14 x i8] c"open() failed\00"
@.str.2 = [5 x i8] c"%lx\0A\00"
@.str.3 = [15 x i8] c"write() failed\00"
define void @set_default_dscr(i64 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %0)
%12 = call i32 @strlen(i8* %3)
%13 = call i32 @write(i32 %5, i8* %3, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = call i32 @close(i32 %5)
ret void
}