#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int name_len;
  char *name;
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ drm_version_t;

/* Variables and functions */
int /*<<< orphan*/ DRM_IOCTL_VERSION;
int ioctl(int, int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ strcmp(char *, char *);
int check_vgem(int fd) {
  drm_version_t version = {0};
  char name[5];
  int ret;
  version.name_len = 4;
  version.name = name;
  ret = ioctl(fd, DRM_IOCTL_VERSION, &version);
  if (ret)
    return 0;
  return !strcmp(name, "vgem");
}


x86 assembly (clang, -O0):
<check_vgem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movl   $0x4,-0x20(%rbp)
lea    -0x25(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1188 <check_vgem+0x58>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <check_vgem+0x78>
lea    -0x25(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_vgem>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x4,0x10(%rsp)
lea    0xb(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     1157 <check_vgem+0x47>
add    $0x28,%rsp
ret
mov    $0x6d656776,%ecx
xor    0xb(%rsp),%ecx
movzbl 0xf(%rsp),%edx
xor    %eax,%eax
or     %ecx,%edx
sete   %al
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@DRM_IOCTL_VERSION = global i32 0
@.str = [5 x i8] c"vgem\00"
define i32 @check_vgem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = alloca [5 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast %struct.TYPE_3__* %4 to i8*
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
store i32 4, i32* %8
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 1
store i8* %9, i8** %10
%11 = load i32, i32* %3
%12 = load i32, i32* @DRM_IOCTL_VERSION
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.TYPE_3__* %4)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 0, i32* %2
br label %23
17: ; preds = %1
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
store i32 %22, i32* %2
br label %23
23: ; preds = %17, %16
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@DRM_IOCTL_VERSION = global i32 0
@.str = [5 x i8] c"vgem\00"
define i32 @check_vgem(i32 %0) {
%2 = alloca %struct.TYPE_3__
%3 = alloca [5 x i8]
%4 = bitcast %struct.TYPE_3__* %2 to i8*
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
store i32 4, i32* %6
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
store i8* %5, i8** %7
%8 = load i32, i32* @DRM_IOCTL_VERSION
%9 = call i32 @ioctl(i32 %0, i32 %8, %struct.TYPE_3__* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @bcmp(i8* dereferenceable(5) %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %1, %11
%16 = phi i32 [ %14, %11 ], [ 0, %1 ]
ret i32 %16
}