#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 int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int write(int, char *, int);
int vibrate(int timeout_ms) {
  char str[20];
  int fd;
  int ret;
  if (timeout_ms > 10000)
    timeout_ms = 1000;
  fd = open("/sys/class/timed_output/vibrator/enable", O_WRONLY);
  if (fd < 0)
    return -1;
  ret = snprintf(str, sizeof(str), "%d", timeout_ms);
  ret = write(fd, str, ret);
  close(fd);
  if (ret < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<vibrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jle    115f <vibrate+0x1f>
movl   $0x3e8,-0x8(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    118d <vibrate+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <vibrate+0x9f>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x14,%esi
lea    0xe88(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x28(%rbp)
jge    11d8 <vibrate+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <vibrate+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vibrate>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a2 <vibrate+0x62>
mov    %eax,%ebx
cmp    $0x2711,%ebp
mov    $0x3e8,%ecx
cmovl  %ebp,%ecx
lea    0xeb0(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x14,%esi
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
sar    $0x1f,%ebp
jmp    11a7 <vibrate+0x67>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"/sys/class/timed_output/vibrator/enable\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @vibrate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 10000
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1000, i32* %3
br label %10
10: ; preds = %9, %1
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %2
br label %30
16: ; preds = %10
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 @snprintf(i8* %17, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %16
store i32 -1, i32* %2
br label %30
29: ; preds = %16
store i32 0, i32* %2
br label %30
30: ; preds = %29, %28, %15
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [40 x i8] c"/sys/class/timed_output/vibrator/enable\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @vibrate(i32 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = icmp sgt i32 %0, 10000
%9 = select i1 %8, i32 1000, i32 %0
%10 = call i32 @snprintf(i8* %3, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @write(i32 %5, i8* %3, i32 %10)
%12 = call i32 @close(i32 %5)
%13 = ashr i32 %11, 31
br label %14
14: ; preds = %7, %1
%15 = phi i32 [ -1, %1 ], [ %13, %7 ]
ret i32 %15
}