#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*/ I2C_SLAVE;
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int write(int, char *, int);
void write_test(int device) {
  char buf[10];
  buf[0] = 0xDE;
  buf[1] = 0xF1;
  buf[2] = 0xD6;
  if (ioctl(device, I2C_SLAVE, 0x12) < 0) {
    perror("ioctl() I2C_SLAVE failed\n");
    return;
  }
  if (write(device, buf, 3) != 3) {
    printf("Error could not write buffer to slave...\n");
    return;
  } else {
    printf("Wrote buffer to slave...\n");
  }
}


x86 assembly (clang, -O0):
<write_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0xde,-0xe(%rbp)
movb   $0xf1,-0xd(%rbp)
movb   $0xd6,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    $0x12,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1188 <write_test+0x48>
lea    0xe82(%rip),%rdi
call   1060 <perror@plt>
jmp    11bf <write_test+0x7f>
mov    -0x4(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     11b3 <write_test+0x73>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
jmp    11bf <write_test+0x7f>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_test>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movw   $0xf1de,0x6(%rsp)
movb   $0xd6,0x8(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    $0x12,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     119b <write_test+0x5b>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1040 <write@plt>
cmp    $0x3,%eax
jne    118a <write_test+0x4a>
lea    0xe92(%rip),%rdi
jmp    1191 <write_test+0x51>
lea    0xea2(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe5e(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <perror@plt>

LLVM IR (-O0):
@I2C_SLAVE = global i32 0
@.str = [26 x i8] c"ioctl() I2C_SLAVE failed\0A\00"
@.str.1 = [42 x i8] c"Error could not write buffer to slave...\0A\00"
@.str.2 = [26 x i8] c"Wrote buffer to slave...\0A\00"
define void @write_test(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 -34, i8* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 -15, i8* %5
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
store i8 -42, i8* %6
%7 = load i32, i32* %2
%8 = load i32, i32* @I2C_SLAVE
%9 = call i64 @ioctl(i32 %7, i32 %8, i32 18)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %22
13: ; preds = %1
%14 = load i32, i32* %2
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 3)
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %11, %18, %20
ret void
}

LLVM IR (-O2):
@I2C_SLAVE = global i32 0
@.str = [26 x i8] c"ioctl() I2C_SLAVE failed\0A\00"
@str = [25 x i8] c"Wrote buffer to slave...\00"
@str.3 = [41 x i8] c"Error could not write buffer to slave...\00"
define void @write_test(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
store i8 -34, i8* %3
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 -15, i8* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 -42, i8* %5
%6 = load i32, i32* @I2C_SLAVE
%7 = tail call i64 @ioctl(i32 %0, i32 %6, i32 18)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %1
%12 = call i32 @write(i32 %0, i8* %3, i32 3)
%13 = icmp eq i32 %12, 3
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0))
br label %18
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14, %9
ret void
}