#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*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int sendit(int timeout_ms) {
  int fd = open("/dev/tspdrv", O_RDWR);
  int timer = timeout_ms;
  int res = 0;
  if (timeout_ms <= 0) {
    res = ioctl(fd, _IO(0x494D4D52 & 0xFF, 4), NULL);
  } else {
    res = ioctl(fd, _IO(0x494D4D52 & 0xFF, 6), &timer);
  }
  close(fd);
  return (res ? -1 : 0);
}


x86 assembly (clang, -O0):
<sendit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     11a5 <sendit+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x52,%edi
mov    $0x4,%esi
call   1030 <_IO@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x10(%rbp)
jmp    11cb <sendit+0x8b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x52,%edi
mov    $0x6,%esi
call   1030 <_IO@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendit>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %ebp,0x4(%rsp)
mov    $0x52,%edi
test   %ebp,%ebp
jle    117e <sendit+0x3e>
mov    $0x6,%esi
call   1030 <_IO@plt>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
jmp    118e <sendit+0x4e>
mov    $0x4,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
neg    %ebp
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/tspdrv\00"
@O_RDWR = global i32 0
define i32 @sendit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %2
store i32 %8, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @_IO(i32 82, i32 4)
%14 = call i32 @ioctl(i32 %12, i32 %13, i32* null)
store i32 %14, i32* %5
br label %19
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @_IO(i32 82, i32 6)
%18 = call i32 @ioctl(i32 %16, i32 %17, i32* %4)
store i32 %18, i32* %5
br label %19
19: ; preds = %15, %11
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 -1, i32 0
ret i32 %25
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/tspdrv\00"
@O_RDWR = global i32 0
define i32 @sendit(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = bitcast i32* %2 to i8*
store i32 %0, i32* %2
%6 = icmp slt i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @_IO(i32 82, i32 4)
%9 = tail call i32 @ioctl(i32 %4, i32 %8, i32* null)
br label %13
10: ; preds = %1
%11 = tail call i32 @_IO(i32 82, i32 6)
%12 = call i32 @ioctl(i32 %4, i32 %11, i32* %2)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ %9, %7 ], [ %12, %10 ]
%15 = call i32 @close(i32 %4)
%16 = icmp ne i32 %14, 0
%17 = sext i1 %16 to i32
ret i32 %17
}