#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;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ write(int, char const *, int);
void console_print(const char *outstr) {
  int fd;
  fd = open("/dev/i2c-2", O_WRONLY);
  if (fd != 0) {
    const char *p;
    ioctl(fd, I2C_SLAVE, 0x44);
    p = outstr;
    while (*p != '\0') {
      write(fd, p, 1);
      p++;
    }
    close(fd);
  }
  printf("%s", outstr);
}


x86 assembly (clang, -O0):
<console_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d6 <console_print+0x86>
mov    -0xc(%rbp),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    $0x44,%edx
call   1050 <ioctl@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ce <console_print+0x7e>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119c <console_print+0x4c>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_print>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
je     11b0 <console_print+0x60>
mov    %eax,%ebp
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    $0x44,%edx
call   1050 <ioctl@plt>
cmpb   $0x0,(%r14)
je     11a9 <console_print+0x59>
mov    %r14,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1190 <console_print+0x40>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_WRONLY = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @console_print(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i32, i32* %3
%11 = load i32, i32* @I2C_SLAVE
%12 = call i32 @ioctl(i32 %10, i32 %11, i32 68)
%13 = load i8*, i8** %2
store i8* %13, i8** %4
br label %14
14: ; preds = %19, %9
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* %3
%21 = load i8*, i8** %4
%22 = call i32 @write(i32 %20, i8* %21, i32 1)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %14
25: ; preds = %14
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %25, %1
%29 = load i8*, i8** %2
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_WRONLY = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @console_print(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = load i32, i32* @I2C_SLAVE
%7 = tail call i32 @ioctl(i32 %3, i32 %6, i32 68)
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5, %10
%11 = phi i8* [ %13, %10 ], [ %0, %5 ]
%12 = tail call i32 @write(i32 %3, i8* %11, i32 1)
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %10, %5
%17 = tail call i32 @close(i32 %3)
br label %18
18: ; preds = %16, %1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret void
}