#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 usd_device {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int close(int);
int errno;
int usd_put_completion_fd(struct usd_device *dev, int comp_fd) {
  if (dev == NULL || comp_fd < 0)
    return -EINVAL;
  if (close(comp_fd) == -1)
    return -errno;
  return 0;
}


x86 assembly (clang, -O0):
<usd_put_completion_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1134 <usd_put_completion_fd+0x24>
cmpl   $0x0,-0x14(%rbp)
jge    1147 <usd_put_completion_fd+0x37>
xor    %eax,%eax
mov    0x2e9b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <usd_put_completion_fd+0x62>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    116b <usd_put_completion_fd+0x5b>
xor    %eax,%eax
mov    0x2e7f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <usd_put_completion_fd+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usd_put_completion_fd>:
push   %rax
test   %rdi,%rdi
je     112c <usd_put_completion_fd+0x1c>
test   %esi,%esi
js     112c <usd_put_completion_fd+0x1c>
mov    %esi,%edi
call   1030 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1135 <usd_put_completion_fd+0x25>
pop    %rcx
ret
mov    0x2ea5(%rip),%rcx
jmp    113c <usd_put_completion_fd+0x2c>
mov    0x2ea4(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.usd_device = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @usd_put_completion_fd(%struct.usd_device* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.usd_device*
%5 = alloca i32
store %struct.usd_device* %0, %struct.usd_device** %4
store i32 %1, i32* %5
%6 = load %struct.usd_device*, %struct.usd_device** %4
%7 = icmp eq %struct.usd_device* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
store i32 %13, i32* %3
br label %22
14: ; preds = %8
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = sub nsw i32 0, %19
store i32 %20, i32* %3
br label %22
21: ; preds = %14
store i32 0, i32* %3
br label %22
22: ; preds = %21, %18, %11
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.usd_device = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @usd_put_completion_fd(%struct.usd_device* readnone %0, i32 %1) {
%3 = icmp eq %struct.usd_device* %0, null
%4 = icmp slt i32 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
br label %15
9: ; preds = %2
%10 = tail call i32 @close(i32 %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
br label %15
15: ; preds = %9, %12, %6
%16 = phi i32 [ %8, %6 ], [ %14, %12 ], [ 0, %9 ]
ret i32 %16
}