#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);
scalar_t__ find_external_mice();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *);
int read_touchpad_data_file(int *palm_check_setting, int *enable_click,
                            int *enable_touchpad, int *disable_for_ext_mouse) {
  int len;
  int fd;
  char file_data[1024];
  *enable_click = 1;
  *palm_check_setting = 3;
  *enable_touchpad = 1;
  *disable_for_ext_mouse = 0;
  fd = open("/data/system"
            "/syntouchpad",
            O_RDONLY);
  if (fd < 0) {
    perror("open data file");
    return 1;
  }
  len = read(fd, file_data, 1024);
  if (len < 0) {
    perror("read data file");
    close(fd);
    return 1;
  }
  sscanf(file_data, "%d\n%d\n%d\n%d", palm_check_setting, enable_click,
         enable_touchpad, disable_for_ext_mouse);
  if (find_external_mice() && *disable_for_ext_mouse) {
    *enable_touchpad = 0;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<read_touchpad_data_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11dd <read_touchpad_data_file+0x7d>
lea    0xe4d(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <read_touchpad_data_file+0x118>
mov    -0x30(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    121e <read_touchpad_data_file+0xbe>
lea    0xe23(%rip),%rdi
call   1080 <perror@plt>
mov    -0x30(%rbp),%edi
call   1030 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <read_touchpad_data_file+0x118>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xdfb(%rip),%rsi
call   1050 <sscanf@plt>
mov    $0x0,%al
call   1060 <find_external_mice@plt>
cmp    $0x0,%rax
je     1269 <read_touchpad_data_file+0x109>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     1269 <read_touchpad_data_file+0x109>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_touchpad_data_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movl   $0x1,(%rsi)
movl   $0x3,(%rdi)
movl   $0x1,(%rdx)
movl   $0x0,(%rcx)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1210 <read_touchpad_data_file+0xb0>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
js     1223 <read_touchpad_data_file+0xc3>
lea    0xe6f(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %r15,%r9
call   1050 <sscanf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <find_external_mice@plt>
test   %rax,%rax
je     11f7 <read_touchpad_data_file+0x97>
cmpl   $0x0,(%r15)
je     11f7 <read_touchpad_data_file+0x97>
movl   $0x0,(%r14)
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe02(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%ebx
jmp    11fe <read_touchpad_data_file+0x9e>
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    $0x1,%ebx
jmp    11fe <read_touchpad_data_file+0x9e>

LLVM IR (-O0):
@.str = [25 x i8] c"/data/system/syntouchpad\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"open data file\00"
@.str.2 = [15 x i8] c"read data file\00"
@.str.3 = [12 x i8] c"%d\0A%d\0A%d\0A%d\00"
define i32 @read_touchpad_data_file(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%13 = load i32*, i32** %7
store i32 1, i32* %13
%14 = load i32*, i32** %6
store i32 3, i32* %14
%15 = load i32*, i32** %8
store i32 1, i32* %15
%16 = load i32*, i32** %9
store i32 0, i32* %16
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %5
br label %51
23: ; preds = %4
%24 = load i32, i32* %11
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 1024)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %11
%32 = call i32 @close(i32 %31)
store i32 1, i32* %5
br label %51
33: ; preds = %23
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%35 = load i32*, i32** %6
%36 = load i32*, i32** %7
%37 = load i32*, i32** %8
%38 = load i32*, i32** %9
%39 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %35, i32* %36, i32* %37, i32* %38)
%40 = call i64 (...) @find_external_mice()
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %33
%43 = load i32*, i32** %9
%44 = load i32, i32* %43
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = load i32*, i32** %8
store i32 0, i32* %47
br label %48
48: ; preds = %46, %42, %33
%49 = load i32, i32* %11
%50 = call i32 @close(i32 %49)
store i32 0, i32* %5
br label %51
51: ; preds = %48, %29, %21
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@.str = [25 x i8] c"/data/system/syntouchpad\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"open data file\00"
@.str.2 = [15 x i8] c"read data file\00"
@.str.3 = [12 x i8] c"%d\0A%d\0A%d\0A%d\00"
define i32 @read_touchpad_data_file(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
store i32 1, i32* %1
store i32 3, i32* %0
store i32 1, i32* %2
store i32 0, i32* %3
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %28
12: ; preds = %4
%13 = call i32 @read(i32 %8, i8* %6, i32 1024)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @close(i32 %8)
br label %28
18: ; preds = %12
%19 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %0, i32* %1, i32* %2, i32* %3)
%20 = tail call i64 (...) @find_external_mice()
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
store i32 0, i32* %2
br label %26
26: ; preds = %25, %22, %18
%27 = tail call i32 @close(i32 %8)
br label %28
28: ; preds = %26, %15, %10
%29 = phi i32 [ 1, %10 ], [ 1, %15 ], [ 0, %26 ]
ret i32 %29
}