#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*/ driver_set_operation(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fsync(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int calibrated_to_driver() {
  int sim_fd = open("/sys/devices/platform/brtablet/data", O_RDWR);
  if (sim_fd < 0) {
    return (-1);
  }
  char buff[2];
  sprintf(buff, "%d", 1);
  buff[1] = 0;
  driver_set_operation("/sys/devices/platform/brtablet/operation", 3, 0);
  fsync(sim_fd);
  write(sim_fd, buff, 2);
  fsync(sim_fd);
  return (0);
}


x86 assembly (clang, -O0):
<calibrated_to_driver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1186 <calibrated_to_driver+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <calibrated_to_driver+0x8a>
lea    -0xa(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x1,%edx
call   1070 <sprintf@plt>
movb   $0x0,-0x9(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <driver_set_operation@plt>
mov    -0x8(%rbp),%edi
call   1050 <fsync@plt>
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <fsync@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calibrated_to_driver>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11c5 <calibrated_to_driver+0x75>
mov    %eax,%ebx
lea    0xeaa(%rip),%rsi
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%edx
call   1070 <sprintf@plt>
movb   $0x0,0xf(%rsp)
lea    0xe8f(%rip),%rdi
xor    %ebp,%ebp
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <driver_set_operation@plt>
mov    %ebx,%edi
call   1050 <fsync@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <fsync@plt>
jmp    11ca <calibrated_to_driver+0x7a>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/devices/platform/brtablet/data\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [41 x i8] c"/sys/devices/platform/brtablet/operation\00"
define i32 @calibrated_to_driver() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %21
9: ; preds = %0
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %12
%13 = call i32 @driver_set_operation(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%14 = load i32, i32* %2
%15 = call i32 @fsync(i32 %14)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 2)
%19 = load i32, i32* %2
%20 = call i32 @fsync(i32 %19)
store i32 0, i32* %1
br label %21
21: ; preds = %9, %8
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/devices/platform/brtablet/data\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [41 x i8] c"/sys/devices/platform/brtablet/operation\00"
define i32 @calibrated_to_driver() {
%1 = alloca [2 x i8]
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
store i8 0, i8* %8
%9 = tail call i32 @driver_set_operation(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%10 = tail call i32 @fsync(i32 %3)
%11 = call i32 @write(i32 %3, i8* %6, i32 2)
%12 = tail call i32 @fsync(i32 %3)
br label %13
13: ; preds = %0, %5
%14 = phi i32 [ 0, %5 ], [ -1, %0 ]
ret i32 %14
}