#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;
  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)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1179 <vibrate+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <vibrate+0x8b>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x14,%esi
lea    0xe9c(%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    11c4 <vibrate+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <vibrate+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vibrate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1198 <vibrate+0x58>
mov    %eax,%ebx
lea    0xebc(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x14,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
sar    $0x1f,%ebp
jmp    119d <vibrate+0x5d>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
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* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %26
12: ; preds = %1
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @snprintf(i8* %13, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %5
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i32 @write(i32 %16, i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 -1, i32* %2
br label %26
25: ; preds = %12
store i32 0, i32* %2
br label %26
26: ; preds = %25, %24, %11
%27 = load i32, i32* %2
ret i32 %27
}

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 %12, label %7
7: ; preds = %1
%8 = call i32 @snprintf(i8* %3, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = call i32 @write(i32 %5, i8* %3, i32 %8)
%10 = call i32 @close(i32 %5)
%11 = ashr i32 %9, 31
br label %12
12: ; preds = %7, %1
%13 = phi i32 [ -1, %1 ], [ %11, %7 ]
ret i32 %13
}