#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_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
void clear_refs(void) {
  int fd;
  char *v = "4";
  fd = open("/proc/self/clear_refs", O_WRONLY);
  if (write(fd, v, 3) < 3) {
    perror("Can't clear soft-dirty bit");
    exit(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<clear_refs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
jge    11ab <clear_refs+0x5b>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_refs>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xe91(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jle    1188 <clear_refs+0x38>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <close@plt>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"4\00"
@.str.1 = [22 x i8] c"/proc/self/clear_refs\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"Can't clear soft-dirty bit\00"
define void @clear_refs() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = load i8*, i8** %2
%7 = call i32 @write(i32 %5, i8* %6, i32 3)
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"4\00"
@.str.1 = [22 x i8] c"/proc/self/clear_refs\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"Can't clear soft-dirty bit\00"
define void @clear_refs() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = icmp slt i32 %3, 3
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @close(i32 %2)
ret void
}