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

/* Variables and functions */
int /*<<< orphan*/ dprintf(int, char *, char const *);
scalar_t__ ioctl(int, int, int);
int parse_device(char const *);
int /*<<< orphan*/ perror(char const *);
int delete_device(int fd, const char *devicename) {
  int dev = parse_device(devicename);
  if (dev < 0) {
    dprintf(2, "ignoring illegal devicename '%s'\n", devicename);
    return 1;
  }
  if (ioctl(fd, 0x4C81, dev) < 0)
    perror(devicename);
  return 0;
}


x86 assembly (clang, -O0):
<delete_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <parse_device@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1186 <delete_device+0x46>
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe8b(%rip),%rsi
call   1040 <dprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <delete_device+0x70>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x4c81,%esi
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11a9 <delete_device+0x69>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_device>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <parse_device@plt>
test   %eax,%eax
js     1173 <delete_device+0x33>
mov    %ebp,%edi
mov    $0x4c81,%esi
mov    %eax,%edx
call   1030 <ioctl@plt>
xor    %ebp,%ebp
test   %rax,%rax
jns    118c <delete_device+0x4c>
mov    %rbx,%rdi
call   1060 <perror@plt>
jmp    118c <delete_device+0x4c>
lea    0xe86(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1040 <dprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"ignoring illegal devicename '%s'\0A\00"
define i32 @delete_device(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @parse_device(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @dprintf(i32 2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %3
br label %23
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i32, i32* %6
%17 = call i64 @ioctl(i32 %15, i32 19585, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 @perror(i8* %20)
br label %22
22: ; preds = %19, %14
store i32 0, i32* %3
br label %23
23: ; preds = %22, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [34 x i8] c"ignoring illegal devicename '%s'\0A\00"
define i32 @delete_device(i32 %0, i8* %1) {
%3 = tail call i32 @parse_device(i8* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @dprintf(i32 2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %12
7: ; preds = %2
%8 = tail call i64 @ioctl(i32 %0, i32 19585, i32 %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* %1)
br label %12
12: ; preds = %7, %10, %5
%13 = phi i32 [ 1, %5 ], [ 0, %10 ], [ 0, %7 ]
ret i32 %13
}