#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 usbdevfs_urb {
  int status;
  char *buffer;
  int buffer_length;
  int endpoint;
  char *usercontext;
  int /*<<< orphan*/ type;
};

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ USBDEVFS_SUBMITURB;
int /*<<< orphan*/ USBDEVFS_URB_TYPE_BULK;
struct usbdevfs_urb *calloc(int, int);
scalar_t__ errno;
int ioctl(int, int /*<<< orphan*/, struct usbdevfs_urb *);
int /*<<< orphan*/ memset(struct usbdevfs_urb *, int /*<<< orphan*/, int);
int send_char_async(int fd, int endpoint, char msg, char *label) {
  char buffer[256] = {0};
  buffer[0] = msg;
  int length = 1;
  struct usbdevfs_urb *urb = calloc(1, sizeof(struct usbdevfs_urb));
  memset(urb, 0, sizeof(struct usbdevfs_urb));
  int res;
  urb->status = -1;
  urb->buffer = buffer;
  urb->buffer_length = length;
  urb->endpoint = endpoint;
  urb->type = USBDEVFS_URB_TYPE_BULK;
  urb->usercontext = label;
  do {
    res = ioctl(fd, USBDEVFS_SUBMITURB, urb);
  } while ((res < 0) && (errno == EINTR));
  return res;
}


x86 assembly (clang, -O0):
<send_char_async>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
mov    -0x9(%rbp),%al
mov    %al,-0x120(%rbp)
movl   $0x1,-0x124(%rbp)
mov    $0x1,%edi
mov    $0x28,%esi
call   1050 <calloc@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    -0x130(%rbp),%rax
movl   $0xffffffff,(%rax)
lea    -0x120(%rbp),%rcx
mov    -0x130(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x124(%rbp),%ecx
mov    -0x130(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x130(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
mov    -0x130(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x130(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x4(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    -0x130(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x134(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x134(%rbp)
mov    %al,-0x135(%rbp)
jge    1247 <send_char_async+0x117>
mov    0x2da7(%rip),%rax
mov    (%rax),%rax
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x135(%rbp)
mov    -0x135(%rbp),%al
test   $0x1,%al
jne    11f7 <send_char_async+0xc7>
mov    -0x134(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_char_async>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rcx,%r14
mov    %esi,%r15d
mov    %edi,%r12d
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %dl,(%rsp)
mov    $0x1,%edi
mov    $0x28,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
movl   $0xffffffff,0x0(%rbp)
mov    %rsp,%rax
mov    %rax,0x8(%rbp)
movl   $0x1,0x10(%rbp)
mov    %r15d,0x14(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rbp)
mov    %r14,0x18(%rbp)
mov    0x2dda(%rip),%r14
mov    0x2dcb(%rip),%r15
mov    0x2dbc(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14),%esi
mov    %r12d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
jns    123a <send_char_async+0x10a>
mov    (%rbx),%rcx
cmp    %rcx,(%r15)
je     1220 <send_char_async+0xf0>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.usbdevfs_urb = type { i32, i8*, i32, i32, i8*, i32 }
@USBDEVFS_URB_TYPE_BULK = global i32 0
@USBDEVFS_SUBMITURB = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @send_char_async(i32 %0, i32 %1, i8 signext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca %struct.usbdevfs_urb*
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i8* %3, i8** %8
%13 = bitcast [256 x i8]* %9 to i8*
%14 = load i8, i8* %7
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8 %14, i8* %15
store i32 1, i32* %10
%16 = call %struct.usbdevfs_urb* @calloc(i32 1, i32 40)
store %struct.usbdevfs_urb* %16, %struct.usbdevfs_urb** %11
%17 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%18 = call i32 @memset(%struct.usbdevfs_urb* %17, i32 0, i32 40)
%19 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%20 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %19, i32 0, i32 0
store i32 -1, i32* %20
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%23 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %22, i32 0, i32 1
store i8* %21, i8** %23
%24 = load i32, i32* %10
%25 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%26 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %25, i32 0, i32 2
store i32 %24, i32* %26
%27 = load i32, i32* %6
%28 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%29 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %28, i32 0, i32 3
store i32 %27, i32* %29
%30 = load i32, i32* @USBDEVFS_URB_TYPE_BULK
%31 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%32 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %31, i32 0, i32 5
store i32 %30, i32* %32
%33 = load i8*, i8** %8
%34 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%35 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %34, i32 0, i32 4
store i8* %33, i8** %35
br label %36
36: ; preds = %48, %4
%37 = load i32, i32* %5
%38 = load i32, i32* @USBDEVFS_SUBMITURB
%39 = load %struct.usbdevfs_urb*, %struct.usbdevfs_urb** %11
%40 = call i32 @ioctl(i32 %37, i32 %38, %struct.usbdevfs_urb* %39)
store i32 %40, i32* %12
br label %41
41: ; preds = %36
%42 = load i32, i32* %12
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINTR
%47 = icmp eq i64 %45, %46
br label %48
48: ; preds = %44, %41
%49 = phi i1 [ false, %41 ], [ %47, %44 ]
br i1 %49, label %36, label %50
50: ; preds = %48
%51 = load i32, i32* %12
ret i32 %51
}

LLVM IR (-O2):
%struct.usbdevfs_urb = type { i32, i8*, i32, i32, i8*, i32 }
@USBDEVFS_URB_TYPE_BULK = global i32 0
@USBDEVFS_SUBMITURB = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @send_char_async(i32 %0, i32 %1, i8 signext %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8 %2, i8* %6
%7 = tail call %struct.usbdevfs_urb* @calloc(i32 1, i32 40)
%8 = tail call i32 @memset(%struct.usbdevfs_urb* %7, i32 0, i32 40)
%9 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 0
store i32 -1, i32* %9
%10 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 1
store i8* %6, i8** %10
%11 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 2
store i32 1, i32* %11
%12 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 3
store i32 %1, i32* %12
%13 = load i32, i32* @USBDEVFS_URB_TYPE_BULK
%14 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 5
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.usbdevfs_urb, %struct.usbdevfs_urb* %7, i64 0, i32 4
store i8* %3, i8** %15
br label %16
16: ; preds = %16, %4
%17 = load i32, i32* @USBDEVFS_SUBMITURB
%18 = call i32 @ioctl(i32 %0, i32 %17, %struct.usbdevfs_urb* %7)
%19 = icmp slt i32 %18, 0
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
%23 = select i1 %19, i1 %22, i1 false
br i1 %23, label %16, label %24
24: ; preds = %16
ret i32 %18
}