#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 cxl_ioctl_start_work {
  int /*<<< orphan*/ flags;
  scalar_t__ amr;
};
typedef scalar_t__ __u64;

/* Variables and functions */
int /*<<< orphan*/ CXL_START_WORK_AMR;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int cxl_work_set_amr(struct cxl_ioctl_start_work *work, __u64 amr) {
  if (work == NULL) {
    errno = EINVAL;
    return -1;
  }
  work->amr = amr;
  if (amr)
    work->flags |= CXL_START_WORK_AMR;
  else
    work->flags &= ~(CXL_START_WORK_AMR);
  return 0;
}


x86 assembly (clang, -O0):
<cxl_work_set_amr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1135 <cxl_work_set_amr+0x35>
mov    0x2eb2(%rip),%rax
mov    (%rax),%ecx
mov    0x2eb1(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <cxl_work_set_amr+0x7d>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1162 <cxl_work_set_amr+0x62>
mov    0x2ea5(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    1176 <cxl_work_set_amr+0x76>
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_work_set_amr>:
test   %rdi,%rdi
je     111c <cxl_work_set_amr+0x1c>
mov    %rsi,0x8(%rdi)
mov    0x2ee8(%rip),%rax
mov    (%rax),%eax
test   %rsi,%rsi
je     1134 <cxl_work_set_amr+0x34>
or     %eax,(%rdi)
xor    %eax,%eax
ret
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2eac(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
not    %eax
and    %eax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.cxl_ioctl_start_work = type { i32, i64 }
@EINVAL = global i32 0
@errno = global i32 0
@CXL_START_WORK_AMR = global i32 0
define i32 @cxl_work_set_amr(%struct.cxl_ioctl_start_work* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.cxl_ioctl_start_work*
%5 = alloca i64
store %struct.cxl_ioctl_start_work* %0, %struct.cxl_ioctl_start_work** %4
store i64 %1, i64* %5
%6 = load %struct.cxl_ioctl_start_work*, %struct.cxl_ioctl_start_work** %4
%7 = icmp eq %struct.cxl_ioctl_start_work* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
store i32 -1, i32* %3
br label %30
10: ; preds = %2
%11 = load i64, i64* %5
%12 = load %struct.cxl_ioctl_start_work*, %struct.cxl_ioctl_start_work** %4
%13 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %12, i32 0, i32 1
store i64 %11, i64* %13
%14 = load i64, i64* %5
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load i32, i32* @CXL_START_WORK_AMR
%18 = load %struct.cxl_ioctl_start_work*, %struct.cxl_ioctl_start_work** %4
%19 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %20, %17
store i32 %21, i32* %19
br label %29
22: ; preds = %10
%23 = load i32, i32* @CXL_START_WORK_AMR
%24 = xor i32 %23, -1
%25 = load %struct.cxl_ioctl_start_work*, %struct.cxl_ioctl_start_work** %4
%26 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %27, %24
store i32 %28, i32* %26
br label %29
29: ; preds = %22, %16
store i32 0, i32* %3
br label %30
30: ; preds = %29, %8
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.cxl_ioctl_start_work = type { i32, i64 }
@EINVAL = global i32 0
@errno = global i32 0
@CXL_START_WORK_AMR = global i32 0
define i32 @cxl_work_set_amr(%struct.cxl_ioctl_start_work* %0, i64 %1) {
%3 = icmp eq %struct.cxl_ioctl_start_work* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EINVAL
store i32 %5, i32* @errno
br label %19
6: ; preds = %2
%7 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %0, i64 0, i32 1
store i64 %1, i64* %7
%8 = icmp eq i64 %1, 0
%9 = load i32, i32* @CXL_START_WORK_AMR
br i1 %8, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = or i32 %12, %9
store i32 %13, i32* %11
br label %19
14: ; preds = %6
%15 = xor i32 %9, -1
%16 = getelementptr inbounds %struct.cxl_ioctl_start_work, %struct.cxl_ioctl_start_work* %0, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
br label %19
19: ; preds = %10, %14, %4
%20 = phi i32 [ -1, %4 ], [ 0, %14 ], [ 0, %10 ]
ret i32 %20
}