#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*/ USBDEVFS_RESET;
int ioctl(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void reset_device(int fd) {
  int res;
  res = ioctl(fd, USBDEVFS_RESET);
  if (!res) {
    printf("OK: USBDEVFS_RESET succeeded\n");
  } else
    printf("ERROR: reset failed! (%d - %s)\n", -res, strerror(-res));
}


x86 assembly (clang, -O0):
<reset_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
call   1040 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    116c <reset_device+0x3c>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <reset_device+0x62>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %edi,%edi
sub    -0x8(%rbp),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_device>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
call   1050 <ioctl@plt>
test   %eax,%eax
je     1172 <reset_device+0x32>
mov    %eax,%ebx
neg    %ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
lea    0xea7(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@USBDEVFS_RESET = global i32 0
@.str = [30 x i8] c"OK: USBDEVFS_RESET succeeded\0A\00"
@.str.1 = [32 x i8] c"ERROR: reset failed! (%d - %s)\0A\00"
define void @reset_device(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @USBDEVFS_RESET
%6 = call i32 @ioctl(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sub nsw i32 0, %12
%14 = load i32, i32* %3
%15 = sub nsw i32 0, %14
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %16)
br label %18
18: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@USBDEVFS_RESET = global i32 0
@.str.1 = [32 x i8] c"ERROR: reset failed! (%d - %s)\0A\00"
@str = [29 x i8] c"OK: USBDEVFS_RESET succeeded\00"
define void @reset_device(i32 %0) {
%2 = load i32, i32* @USBDEVFS_RESET
%3 = tail call i32 @ioctl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %11
7: ; preds = %1
%8 = sub nsw i32 0, %3
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* %9)
br label %11
11: ; preds = %7, %5
ret void
}