#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*/ descr;

/* Variables and functions */
int /*<<< orphan*/ EVIOCGNAME(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
char *strdup(char *);
char *get_device_description(int fd) {
  char descr[256] = "Unknown";
  if (ioctl(fd, EVIOCGNAME(sizeof(descr)), descr) < 0) {
    perror("evdev ioctl");
  }
  return strdup(descr);
}


x86 assembly (clang, -O0):
<get_device_description>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe94(%rip),%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x114(%rbp)
mov    $0x100,%edi
call   1060 <EVIOCGNAME@plt>
mov    -0x114(%rbp),%edi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11b3 <get_device_description+0x63>
lea    0xf52(%rip),%rdi
call   1050 <perror@plt>
lea    -0x110(%rbp),%rdi
call   1070 <strdup@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_device_description>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
lea    0xe9d(%rip),%rsi
mov    %rsp,%r14
mov    $0x100,%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    $0x100,%edi
call   1060 <EVIOCGNAME@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     11a1 <get_device_description+0x51>
mov    %rsp,%rdi
call   1070 <strdup@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xf58(%rip),%rdi
call   1050 <perror@plt>
jmp    118e <get_device_description+0x3e>

LLVM IR (-O0):
@__const.get_device_description.descr = [256 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"evdev ioctl\00"
define i8* @get_device_description(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
store i32 %0, i32* %2
%4 = bitcast [256 x i8]* %3 to i8*
%5 = load i32, i32* %2
%6 = call i32 @EVIOCGNAME(i32 256)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = call i64 @ioctl(i32 %5, i32 %6, i8* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = call i8* @strdup(i8* %13)
ret i8* %14
}

LLVM IR (-O2):
@__const.get_device_description.descr = [256 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"evdev ioctl\00"
define noalias i8* @get_device_description(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @EVIOCGNAME(i32 256)
%5 = call i64 @ioctl(i32 %0, i32 %4, i8* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i8* @strdup(i8* %3)
ret i8* %10
}