#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*/ uinput_device;
struct input_id {
  int dummy;
};
struct uinput_user_dev {
  int /*<<< orphan*/ name;
  struct input_id const id;
};

/* Variables and functions */
int /*<<< orphan*/ UINPUT_MAX_NAME_SIZE;
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                            char const *);
int write(int, struct uinput_user_dev *, int);
int setup_uinput_device_v1(int uinput_fd, const char *device_name,
                           const struct input_id *device_input_id) {
  struct uinput_user_dev uinput_device = {.id = *device_input_id};
  snprintf(uinput_device.name, UINPUT_MAX_NAME_SIZE, "%s", device_name);
  return write(uinput_fd, &uinput_device, sizeof(uinput_device));
}


x86 assembly (clang, -O0):
<setup_uinput_device_v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xea6(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_uinput_device_v1>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rcx
mov    %edi,%ebx
movl   $0x0,0x8(%rsp)
mov    (%rdx),%eax
mov    %eax,0xc(%rsp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdx
xor    %edi,%edi
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.input_id = type { i32 }
%struct.uinput_user_dev = type { i32, %struct.input_id }
@UINPUT_MAX_NAME_SIZE = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @setup_uinput_device_v1(i32 %0, i8* %1, %struct.input_id* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.input_id*
%7 = alloca %struct.uinput_user_dev
store i32 %0, i32* %4
store i8* %1, i8** %5
store %struct.input_id* %2, %struct.input_id** %6
%8 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %7, i32 0, i32 0
store i32 0, i32* %8
%9 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %7, i32 0, i32 1
%10 = load %struct.input_id*, %struct.input_id** %6
%11 = bitcast %struct.input_id* %9 to i8*
%12 = bitcast %struct.input_id* %10 to i8*
%13 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %7, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @UINPUT_MAX_NAME_SIZE
%16 = load i8*, i8** %5
%17 = call i32 @snprintf(i32 %14, i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
%19 = call i32 @write(i32 %18, %struct.uinput_user_dev* %7, i32 8)
ret i32 %19
}

LLVM IR (-O2):
%struct.input_id = type { i32 }
%struct.uinput_user_dev = type { i32, %struct.input_id }
@UINPUT_MAX_NAME_SIZE = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @setup_uinput_device_v1(i32 %0, i8* %1, %struct.input_id* nocapture %2) {
%4 = alloca %struct.uinput_user_dev
%5 = bitcast %struct.uinput_user_dev* %4 to i8*
%6 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %4, i64 0, i32 0
store i32 0, i32* %6
%7 = getelementptr %struct.input_id, %struct.input_id* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.uinput_user_dev, %struct.uinput_user_dev* %4, i64 0, i32 1, i32 0
%9 = load i32, i32* %7
store i32 %9, i32* %8
%10 = load i32, i32* @UINPUT_MAX_NAME_SIZE
%11 = tail call i32 @snprintf(i32 0, i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%12 = call i32 @write(i32 %0, %struct.uinput_user_dev* %4, i32 8)
ret i32 %12
}