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

/* Variables and functions */
int /*<<< orphan*/ _IOW(unsigned char, int, int /*<<< orphan*/);
int /*<<< orphan*/ __u32;
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void drop_privileges(int fd, uint32_t mask) {
  int res;
  res = ioctl(fd, _IOW('U', 30, __u32), &mask);
  if (res)
    printf("ERROR: USBDEVFS_DROP_PRIVILEGES returned %d\n", res);
  else
    printf("OK: privileges dropped!\n");
}


x86 assembly (clang, -O0):
<drop_privileges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    $0x55,%edi
mov    $0x1e,%esi
call   1030 <_IOW@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     118d <drop_privileges+0x5d>
mov    -0xc(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119b <drop_privileges+0x6b>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drop_privileges>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    $0x55,%edi
mov    $0x1e,%esi
call   1040 <_IOW@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %eax,%eax
je     1187 <drop_privileges+0x47>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1193 <drop_privileges+0x53>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__u32 = global i32 0
@.str = [45 x i8] c"ERROR: USBDEVFS_DROP_PRIVILEGES returned %d\0A\00"
@.str.1 = [25 x i8] c"OK: privileges dropped!\0A\00"
define void @drop_privileges(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @__u32
%8 = call i32 @_IOW(i8 zeroext 85, i32 30, i32 %7)
%9 = call i32 @ioctl(i32 %6, i32 %8, i32* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
@__u32 = global i32 0
@.str = [45 x i8] c"ERROR: USBDEVFS_DROP_PRIVILEGES returned %d\0A\00"
@str = [24 x i8] c"OK: privileges dropped!\00"
define void @drop_privileges(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = load i32, i32* @__u32
%5 = tail call i32 @_IOW(i8 zeroext 85, i32 30, i32 %4)
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %12
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
ret void
}