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

/* Variables and functions */
int ENODEV;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int igvt_destroy_instance(unsigned int domid) {
  FILE *fd;
  char *path = "/sys/kernel/vgt"
               "/control/create_vgt_instance";
  int retval = 0;
  fd = fopen(path, "w");
  if (!fd)
    return -ENODEV;
  if (fprintf(fd, "%d\n", -domid) < 0) {
    retval = -errno;
  }
  fclose(fd);
  return retval;
}


x86 assembly (clang, -O0):
<igvt_destroy_instance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xed4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <igvt_destroy_instance+0x4f>
xor    %eax,%eax
mov    0x2e63(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11bb <igvt_destroy_instance+0x8b>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
sub    -0x8(%rbp),%edx
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jge    11ac <igvt_destroy_instance+0x7c>
xor    %eax,%eax
mov    0x2e39(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<igvt_destroy_instance>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec3(%rip),%rdi
lea    0xee8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1182 <igvt_destroy_instance+0x52>
mov    %rax,%r14
neg    %ebx
lea    0xed4(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %rax,%rbx
mov    0x2e72(%rip),%rax
xor    %ecx,%ecx
sub    (%rax),%ecx
sar    $0x3f,%rbx
and    %ecx,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    118d <igvt_destroy_instance+0x5d>
mov    0x2e4f(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [44 x i8] c"/sys/kernel/vgt/control/create_vgt_instance\00"
@.str.1 = [2 x i8] c"w\00"
@ENODEV = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
define i32 @igvt_destroy_instance(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %6
%7 = load i8*, i8** %5
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* @ENODEV
%13 = sub nsw i32 0, %12
store i32 %13, i32* %2
br label %27
14: ; preds = %1
%15 = load i32*, i32** %4
%16 = load i32, i32* %3
%17 = sub i32 0, %16
%18 = call i64 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @errno
%22 = sub nsw i32 0, %21
store i32 %22, i32* %6
br label %23
23: ; preds = %20, %14
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %6
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %11
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [44 x i8] c"/sys/kernel/vgt/control/create_vgt_instance\00"
@.str.1 = [2 x i8] c"w\00"
@ENODEV = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
define i32 @igvt_destroy_instance(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @ENODEV
%6 = sub nsw i32 0, %5
br label %15
7: ; preds = %1
%8 = sub i32 0, %0
%9 = tail call i64 @fprintf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp slt i64 %9, 0
%11 = load i32, i32* @errno
%12 = sub nsw i32 0, %11
%13 = select i1 %10, i32 %12, i32 0
%14 = tail call i32 @fclose(i32* %2)
br label %15
15: ; preds = %7, %4
%16 = phi i32 [ %13, %7 ], [ %6, %4 ]
ret i32 %16
}