#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 can_frame {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
scalar_t__ ENOBUFS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int write(int, struct can_frame *, int);
int can_send_frame(int fd, struct can_frame *msg) {
  ssize_t len;
  do {
    len = write(fd, msg, sizeof(struct can_frame));
    usleep(10000);
  } while (len < 0 && errno == ENOBUFS);
  if (len < 0) {
    perror("Writing to can socket failed");
    return -1;
  }
  if (len != sizeof(struct can_frame)) {
    do {
      fprintf(stderr, "Was unable to send whole can frame"
                      "\n");
    } while (0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<can_send_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    $0x2710,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jge    1196 <can_send_frame+0x56>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    114f <can_send_frame+0xf>
cmpl   $0x0,-0x14(%rbp)
jge    11c3 <can_send_frame+0x83>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <can_send_frame+0xbe>
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
je     11f7 <can_send_frame+0xb7>
jmp    11d6 <can_send_frame+0x96>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <can_send_frame+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<can_send_frame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e7c(%rip),%r15
mov    0x2e9d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    $0x2710,%edi
call   1060 <usleep@plt>
test   %ebx,%ebx
jns    1188 <can_send_frame+0x48>
mov    (%r12),%rax
cmp    %rax,(%r15)
je     1160 <can_send_frame+0x20>
test   %ebx,%ebx
js     11b6 <can_send_frame+0x76>
xor    %eax,%eax
cmp    $0x4,%ebx
je     11ad <can_send_frame+0x6d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
jmp    11a8 <can_send_frame+0x68>

LLVM IR (-O0):
%struct.can_frame = type { i32 }
@errno = global i64 0
@ENOBUFS = global i64 0
@.str = [29 x i8] c"Writing to can socket failed\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Was unable to send whole can frame\0A\00"
define i32 @can_send_frame(i32 %0, %struct.can_frame* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.can_frame*
%6 = alloca i32
store i32 %0, i32* %4
store %struct.can_frame* %1, %struct.can_frame** %5
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %4
%9 = load %struct.can_frame*, %struct.can_frame** %5
%10 = call i32 @write(i32 %8, %struct.can_frame* %9, i32 4)
store i32 %10, i32* %6
%11 = call i32 @usleep(i32 10000)
br label %12
12: ; preds = %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOBUFS
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %7, label %21
21: ; preds = %19
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
26: ; preds = %21
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = icmp ne i64 %28, 4
br i1 %29, label %30, label %35
30: ; preds = %26
br label %31
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31
store i32 -1, i32* %3
br label %36
35: ; preds = %26
store i32 0, i32* %3
br label %36
36: ; preds = %35, %34, %24
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.can_frame = type { i32 }
@errno = global i64 0
@ENOBUFS = global i64 0
@.str = [29 x i8] c"Writing to can socket failed\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Was unable to send whole can frame\0A\00"
define i32 @can_send_frame(i32 %0, %struct.can_frame* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 @write(i32 %0, %struct.can_frame* %1, i32 4)
%5 = tail call i32 @usleep(i32 10000)
%6 = icmp slt i32 %4, 0
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOBUFS
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %3, label %11
11: ; preds = %3
br i1 %6, label %12, label %14
12: ; preds = %11
%13 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %19
14: ; preds = %11
%15 = icmp eq i32 %4, 4
br i1 %15, label %19, label %16
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %14, %16, %12
%20 = phi i32 [ -1, %12 ], [ -1, %16 ], [ 0, %14 ]
ret i32 %20
}