#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 */
struct uhid_event {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int write(int, struct uhid_event const *, int);
int uhid_write(int fd, const struct uhid_event *ev) {
  ssize_t ret;
  ret = write(fd, ev, sizeof(*ev));
  if (ret < 0) {
    fprintf(stderr, "Cannot write to uhid: %m\n");
    return -1;
  } else if (ret != sizeof(*ev)) {
    fprintf(stderr, "Wrong size written to uhid: %ld != %lu\n", ret,
            sizeof(*ev));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<uhid_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1170 <uhid_write+0x50>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <uhid_write+0x95>
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
je     11a9 <uhid_write+0x89>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe89(%rip),%rsi
mov    $0x4,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <uhid_write+0x95>
jmp    11ae <uhid_write+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uhid_write>:
push   %rax
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1156 <uhid_write+0x36>
xor    %ecx,%ecx
cmp    $0x4,%eax
je     1172 <uhid_write+0x52>
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%edi
lea    0xed4(%rip),%rsi
mov    $0x4,%ecx
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    116d <uhid_write+0x4d>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.uhid_event = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Cannot write to uhid: %m\0A\00"
@.str.1 = [40 x i8] c"Wrong size written to uhid: %ld != %lu\0A\00"
define i32 @uhid_write(i32 %0, %struct.uhid_event* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.uhid_event*
%6 = alloca i32
store i32 %0, i32* %4
store %struct.uhid_event* %1, %struct.uhid_event** %5
%7 = load i32, i32* %4
%8 = load %struct.uhid_event*, %struct.uhid_event** %5
%9 = call i32 @write(i32 %7, %struct.uhid_event* %8, i32 4)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
15: ; preds = %2
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = icmp ne i64 %17, 4
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* %6
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %21, i64 4)
store i32 -1, i32* %3
br label %25
23: ; preds = %15
br label %24
24: ; preds = %23
store i32 0, i32* %3
br label %25
25: ; preds = %24, %19, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.uhid_event = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Cannot write to uhid: %m\0A\00"
@.str.1 = [40 x i8] c"Wrong size written to uhid: %ld != %lu\0A\00"
define i32 @uhid_write(i32 %0, %struct.uhid_event* nocapture %1) {
%3 = tail call i32 @write(i32 %0, %struct.uhid_event* %1, i32 4)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %2
%9 = icmp eq i32 %3, 4
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %3, i64 4)
br label %13
13: ; preds = %8, %10, %5
%14 = phi i32 [ -1, %5 ], [ -1, %10 ], [ 0, %8 ]
ret i32 %14
}