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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
void writeToDevice(int i2c, char *buf, int len) {
  static int reported = 0;
  if (write(i2c, buf, len) != len) {
    if (!reported) {
      fprintf(stderr, "Can't write to device\n");
      reported = 1;
    }
  } else
    reported = 0;
}


x86 assembly (clang, -O0):
<writeToDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     117b <writeToDevice+0x5b>
cmpl   $0x0,0x2ee3(%rip)
jne    1176 <writeToDevice+0x56>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,0x2ebe(%rip)
jmp    1185 <writeToDevice+0x65>
movl   $0x0,0x2eaf(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToDevice>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
call   1030 <write@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
je     114e <writeToDevice+0x2e>
cmpb   $0x0,0x2efd(%rip)
jne    1157 <writeToDevice+0x37>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1040 <fprintf@plt>
cmp    %ebx,%ebp
setne  0x2edd(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@writeToDevice.reported = internal global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Can't write to device\0A\00"
define void @writeToDevice(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 @write(i32 %7, i8* %8, i32 %9)
%11 = load i32, i32* %6
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* @writeToDevice.reported
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* @writeToDevice.reported
br label %19
19: ; preds = %16, %13
br label %21
20: ; preds = %3
store i32 0, i32* @writeToDevice.reported
br label %21
21: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
@writeToDevice.reported = internal unnamed_addr global i1 false
@stderr = global i32 0
@.str = [23 x i8] c"Can't write to device\0A\00"
define void @writeToDevice(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%5 = icmp eq i32 %4, %2
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i1, i1* @writeToDevice.reported
br i1 %7, label %13, label %8
8: ; preds = %6
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %3, %8
%12 = xor i1 %5, true
store i1 %12, i1* @writeToDevice.reported
br label %13
13: ; preds = %11, %6
ret void
}