#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*/ uint16_t;
struct input_id {
  int /*<<< orphan*/ version;
  int /*<<< orphan*/ product;
  int /*<<< orphan*/ vendor;
  int /*<<< orphan*/ bustype;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
scalar_t__ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int write_input_id(FILE *fout, const struct input_id *id) {
  int ret = 0;
  ret += fwrite(&id->bustype, sizeof(uint16_t), 1, fout);
  ret += fwrite(&id->vendor, sizeof(uint16_t), 1, fout);
  ret += fwrite(&id->product, sizeof(uint16_t), 1, fout);
  ret += fwrite(&id->version, sizeof(uint16_t), 1, fout);
  if (ret < 4)
    return errno;
  return 0;
}


x86 assembly (clang, -O0):
<write_input_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0xc,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11de <write_input_id+0xce>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <write_input_id+0xd5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_input_id>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xc(%rsi),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fwrite@plt>
mov    %rax,%r15
lea    0x8(%r12),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fwrite@plt>
mov    %rax,%r13
add    %r15d,%r13d
lea    0x4(%r12),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fwrite@plt>
mov    %rax,%rbx
add    %r13d,%ebx
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fwrite@plt>
mov    %rax,%rcx
add    %ebx,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jge    119c <write_input_id+0x8c>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.input_id = type { i32, i32, i32, i32 }
@errno = global i32 0
define i32 @write_input_id(i32* %0, %struct.input_id* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.input_id*
%6 = alloca i32
store i32* %0, i32** %4
store %struct.input_id* %1, %struct.input_id** %5
store i32 0, i32* %6
%7 = load %struct.input_id*, %struct.input_id** %5
%8 = getelementptr inbounds %struct.input_id, %struct.input_id* %7, i32 0, i32 3
%9 = load i32*, i32** %4
%10 = call i64 @fwrite(i32* %8, i32 4, i32 1, i32* %9)
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %6
%15 = load %struct.input_id*, %struct.input_id** %5
%16 = getelementptr inbounds %struct.input_id, %struct.input_id* %15, i32 0, i32 2
%17 = load i32*, i32** %4
%18 = call i64 @fwrite(i32* %16, i32 4, i32 1, i32* %17)
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %6
%23 = load %struct.input_id*, %struct.input_id** %5
%24 = getelementptr inbounds %struct.input_id, %struct.input_id* %23, i32 0, i32 1
%25 = load i32*, i32** %4
%26 = call i64 @fwrite(i32* %24, i32 4, i32 1, i32* %25)
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %6
%31 = load %struct.input_id*, %struct.input_id** %5
%32 = getelementptr inbounds %struct.input_id, %struct.input_id* %31, i32 0, i32 0
%33 = load i32*, i32** %4
%34 = call i64 @fwrite(i32* %32, i32 4, i32 1, i32* %33)
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %43
41: ; preds = %2
%42 = load i32, i32* @errno
store i32 %42, i32* %3
br label %44
43: ; preds = %2
store i32 0, i32* %3
br label %44
44: ; preds = %43, %41
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.input_id = type { i32, i32, i32, i32 }
@errno = global i32 0
define i32 @write_input_id(i32* nocapture %0, %struct.input_id* nocapture %1) {
%3 = getelementptr inbounds %struct.input_id, %struct.input_id* %1, i64 0, i32 3
%4 = tail call i64 @fwrite(i32* %3, i32 4, i32 1, i32* %0)
%5 = getelementptr inbounds %struct.input_id, %struct.input_id* %1, i64 0, i32 2
%6 = tail call i64 @fwrite(i32* %5, i32 4, i32 1, i32* %0)
%7 = add i64 %6, %4
%8 = getelementptr inbounds %struct.input_id, %struct.input_id* %1, i64 0, i32 1
%9 = tail call i64 @fwrite(i32* %8, i32 4, i32 1, i32* %0)
%10 = add i64 %7, %9
%11 = getelementptr inbounds %struct.input_id, %struct.input_id* %1, i64 0, i32 0
%12 = tail call i64 @fwrite(i32* %11, i32 4, i32 1, i32* %0)
%13 = add i64 %10, %12
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %14, 4
%16 = load i32, i32* @errno
%17 = select i1 %15, i32 %16, i32 0
ret i32 %17
}