#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 */
struct pci_device {
  int bus;
  int dev;
  int func;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int, int);
scalar_t__ pci_device_bind_uio_driver(struct pci_device *, char *);
char *pci_device_get_device_name(struct pci_device *);
scalar_t__ pci_device_unbind_kernel_driver(struct pci_device *);
int /*<<< orphan*/ printf(char *, char *, int, int, int);
int /*<<< orphan*/ stderr;
int pci_device_switch_to_uio_driver(struct pci_device *pci_dev) {
  if (pci_device_unbind_kernel_driver(pci_dev)) {
    fprintf(stderr,
            "Device %s %d:%d:%d unbind from "
            "kernel driver failed\n",
            pci_device_get_device_name(pci_dev), pci_dev->bus, pci_dev->dev,
            pci_dev->func);
    return -1;
  }
  if (pci_device_bind_uio_driver(pci_dev, "uio_pci_generic")) {
    fprintf(stderr,
            "Device %s %d:%d:%d bind to "
            "uio driver failed\n",
            pci_device_get_device_name(pci_dev), pci_dev->bus, pci_dev->dev,
            pci_dev->func);
    return -1;
  }
  printf("Device %s %d:%d:%d bind to uio driver success\n",
         pci_device_get_device_name(pci_dev), pci_dev->bus, pci_dev->dev,
         pci_dev->func);
  return 0;
}


x86 assembly (clang, -O0):
<pci_device_switch_to_uio_driver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <pci_device_unbind_kernel_driver@plt>
cmp    $0x0,%rax
je     11b8 <pci_device_switch_to_uio_driver+0x68>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pci_device_get_device_name@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r9d
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <pci_device_switch_to_uio_driver+0xff>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <pci_device_bind_uio_driver@plt>
cmp    $0x0,%rax
je     121b <pci_device_switch_to_uio_driver+0xcb>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pci_device_get_device_name@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r9d
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <pci_device_switch_to_uio_driver+0xff>
mov    -0x10(%rbp),%rdi
call   1040 <pci_device_get_device_name@plt>
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pci_device_switch_to_uio_driver>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <pci_device_unbind_kernel_driver@plt>
test   %rax,%rax
je     1184 <pci_device_switch_to_uio_driver+0x34>
mov    0x2e79(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <pci_device_get_device_name@plt>
mov    (%rbx),%ecx
mov    0x4(%rbx),%r8d
mov    0x8(%rbx),%r9d
lea    0xe7e(%rip),%rsi
jmp    11ba <pci_device_switch_to_uio_driver+0x6a>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1070 <pci_device_bind_uio_driver@plt>
test   %rax,%rax
je     11d0 <pci_device_switch_to_uio_driver+0x80>
mov    0x2e41(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <pci_device_get_device_name@plt>
mov    (%rbx),%ecx
mov    0x4(%rbx),%r8d
mov    0x8(%rbx),%r9d
lea    0xe8b(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <pci_device_get_device_name@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
lea    0xe8b(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11c9 <pci_device_switch_to_uio_driver+0x79>

LLVM IR (-O0):
%struct.pci_device = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [53 x i8] c"Device %s %d:%d:%d unbind from kernel driver failed\0A\00"
@.str.1 = [16 x i8] c"uio_pci_generic\00"
@.str.2 = [46 x i8] c"Device %s %d:%d:%d bind to uio driver failed\0A\00"
@.str.3 = [47 x i8] c"Device %s %d:%d:%d bind to uio driver success\0A\00"
define i32 @pci_device_switch_to_uio_driver(%struct.pci_device* %0) {
%2 = alloca i32
%3 = alloca %struct.pci_device*
store %struct.pci_device* %0, %struct.pci_device** %3
%4 = load %struct.pci_device*, %struct.pci_device** %3
%5 = call i64 @pci_device_unbind_kernel_driver(%struct.pci_device* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load %struct.pci_device*, %struct.pci_device** %3
%10 = call i8* @pci_device_get_device_name(%struct.pci_device* %9)
%11 = load %struct.pci_device*, %struct.pci_device** %3
%12 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load %struct.pci_device*, %struct.pci_device** %3
%15 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load %struct.pci_device*, %struct.pci_device** %3
%18 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %13, i32 %16, i32 %19)
store i32 -1, i32* %2
br label %52
21: ; preds = %1
%22 = load %struct.pci_device*, %struct.pci_device** %3
%23 = call i64 @pci_device_bind_uio_driver(%struct.pci_device* %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load %struct.pci_device*, %struct.pci_device** %3
%28 = call i8* @pci_device_get_device_name(%struct.pci_device* %27)
%29 = load %struct.pci_device*, %struct.pci_device** %3
%30 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load %struct.pci_device*, %struct.pci_device** %3
%33 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load %struct.pci_device*, %struct.pci_device** %3
%36 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %35, i32 0, i32 2
%37 = load i32, i32* %36
%38 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %31, i32 %34, i32 %37)
store i32 -1, i32* %2
br label %52
39: ; preds = %21
%40 = load %struct.pci_device*, %struct.pci_device** %3
%41 = call i8* @pci_device_get_device_name(%struct.pci_device* %40)
%42 = load %struct.pci_device*, %struct.pci_device** %3
%43 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load %struct.pci_device*, %struct.pci_device** %3
%46 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.pci_device*, %struct.pci_device** %3
%49 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %48, i32 0, i32 2
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %41, i32 %44, i32 %47, i32 %50)
store i32 0, i32* %2
br label %52
52: ; preds = %39, %25, %7
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
%struct.pci_device = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [53 x i8] c"Device %s %d:%d:%d unbind from kernel driver failed\0A\00"
@.str.1 = [16 x i8] c"uio_pci_generic\00"
@.str.2 = [46 x i8] c"Device %s %d:%d:%d bind to uio driver failed\0A\00"
@.str.3 = [47 x i8] c"Device %s %d:%d:%d bind to uio driver success\0A\00"
define i32 @pci_device_switch_to_uio_driver(%struct.pci_device* %0) {
%2 = tail call i64 @pci_device_unbind_kernel_driver(%struct.pci_device* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i8* @pci_device_get_device_name(%struct.pci_device* %0)
%7 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 2
%12 = load i32, i32* %11
%13 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %8, i32 %10, i32 %12)
br label %36
14: ; preds = %1
%15 = tail call i64 @pci_device_bind_uio_driver(%struct.pci_device* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i8* @pci_device_get_device_name(%struct.pci_device* %0)
%20 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 2
%25 = load i32, i32* %24
%26 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 %21, i32 %23, i32 %25)
br label %36
27: ; preds = %14
%28 = tail call i8* @pci_device_get_device_name(%struct.pci_device* %0)
%29 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %0, i64 0, i32 2
%34 = load i32, i32* %33
%35 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 %30, i32 %32, i32 %34)
br label %36
36: ; preds = %27, %17, %4
%37 = phi i32 [ -1, %4 ], [ -1, %17 ], [ 0, %27 ]
ret i32 %37
}