#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_RDWR;
int /*<<< orphan*/ errno;
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ lcdclear(int);
int /*<<< orphan*/ lcdputstring(int, char *);
int /*<<< orphan*/ lcdsend(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ lcdsetcurpos(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strerror(int /*<<< orphan*/);
int main(void) {
  int value;
  int fd;
  int i;
  char stringa[32 + 1];
  fd = open("/dev/i2c-0", O_RDWR);
  if (fd < 0) {
    printf("Error opening file: %s\n", strerror(errno));
    return 1;
  }
  if (ioctl(fd, I2C_SLAVE, 0x3E) < 0) {
    printf("ioctl error: %s\n", strerror(errno));
    return 1;
  }
  lcdsend(fd, 0, 0x38);
  lcdsend(fd, 0, 0x39);
  lcdsend(fd, 0, 0x14);
  lcdsend(fd, 0, 0x72);
  lcdsend(fd, 0, 0x54);
  lcdsend(fd, 0, 0x6F);
  lcdsend(fd, 0, 0x0C);
  lcdclear(fd);
  lcdputstring(fd, "PROVAAAA");
  for (i = 0;; i++) {
    lcdsetcurpos(fd, 0, 1);
    sprintf(stringa, "%08d", i);
    lcdputstring(fd, stringa);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ea <main+0x5a>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f6 <main+0x166>
mov    -0xc(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    $0x3e,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1233 <main+0xa3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f6 <main+0x166>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x38,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x39,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x72,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x54,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x6f,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <lcdsend@plt>
mov    -0xc(%rbp),%edi
call   1080 <lcdclear@plt>
mov    -0xc(%rbp),%edi
lea    0xd86(%rip),%rsi
call   1090 <lcdputstring@plt>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <lcdsetcurpos@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xd66(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1090 <lcdputstring@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12ba <main+0x12a>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     129c <main+0x10c>
mov    %eax,%r15d
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    $0x3e,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     12a5 <main+0x115>
xor    %ebp,%ebp
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x38,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x39,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x72,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x54,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x6f,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <lcdsend@plt>
mov    %r15d,%edi
call   1080 <lcdclear@plt>
lea    0xde1(%rip),%rsi
mov    %r15d,%edi
call   1090 <lcdputstring@plt>
lea    0xddb(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <lcdsetcurpos@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1090 <lcdputstring@plt>
add    $0x1,%ebp
jmp    1270 <main+0xe0>
lea    0xd68(%rip),%rbx
jmp    12ac <main+0x11c>
lea    0xd77(%rip),%rbx
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [17 x i8] c"ioctl error: %s\0A\00"
@.str.3 = [9 x i8] c"PROVAAAA\00"
@.str.4 = [5 x i8] c"%08d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [33 x i8]
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 1, i32* %1
br label %54
14: ; preds = %0
%15 = load i32, i32* %3
%16 = load i32, i32* @I2C_SLAVE
%17 = call i64 @ioctl(i32 %15, i32 %16, i32 62)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
store i32 1, i32* %1
br label %54
23: ; preds = %14
%24 = load i32, i32* %3
%25 = call i32 @lcdsend(i32 %24, i32 0, i32 56)
%26 = load i32, i32* %3
%27 = call i32 @lcdsend(i32 %26, i32 0, i32 57)
%28 = load i32, i32* %3
%29 = call i32 @lcdsend(i32 %28, i32 0, i32 20)
%30 = load i32, i32* %3
%31 = call i32 @lcdsend(i32 %30, i32 0, i32 114)
%32 = load i32, i32* %3
%33 = call i32 @lcdsend(i32 %32, i32 0, i32 84)
%34 = load i32, i32* %3
%35 = call i32 @lcdsend(i32 %34, i32 0, i32 111)
%36 = load i32, i32* %3
%37 = call i32 @lcdsend(i32 %36, i32 0, i32 12)
%38 = load i32, i32* %3
%39 = call i32 @lcdclear(i32 %38)
%40 = load i32, i32* %3
%41 = call i32 @lcdputstring(i32 %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %42
42: ; preds = %51, %23
%43 = load i32, i32* %3
%44 = call i32 @lcdsetcurpos(i32 %43, i32 0, i32 1)
%45 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 0
%46 = load i32, i32* %4
%47 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
%49 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 0
%50 = call i32 @lcdputstring(i32 %48, i8* %49)
br label %51
51: ; preds = %42
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %42
54: ; preds = %19, %10
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [17 x i8] c"ioctl error: %s\0A\00"
@.str.3 = [9 x i8] c"PROVAAAA\00"
@.str.4 = [5 x i8] c"%08d\00"
define i32 @main() {
%1 = alloca [33 x i8]
%2 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %0
%7 = load i32, i32* @I2C_SLAVE
%8 = tail call i64 @ioctl(i32 %4, i32 %7, i32 62)
%9 = icmp slt i64 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %6
%11 = tail call i32 @lcdsend(i32 %4, i32 0, i32 56)
%12 = tail call i32 @lcdsend(i32 %4, i32 0, i32 57)
%13 = tail call i32 @lcdsend(i32 %4, i32 0, i32 20)
%14 = tail call i32 @lcdsend(i32 %4, i32 0, i32 114)
%15 = tail call i32 @lcdsend(i32 %4, i32 0, i32 84)
%16 = tail call i32 @lcdsend(i32 %4, i32 0, i32 111)
%17 = tail call i32 @lcdsend(i32 %4, i32 0, i32 12)
%18 = tail call i32 @lcdclear(i32 %4)
%19 = tail call i32 @lcdputstring(i32 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %20, %10
%21 = phi i32 [ 0, %10 ], [ %25, %20 ]
%22 = call i32 @lcdsetcurpos(i32 %4, i32 0, i32 1)
%23 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%24 = call i32 @lcdputstring(i32 %4, i8* %2)
%25 = add nuw nsw i32 %21, 1
br label %20
26: ; preds = %6, %0
%27 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %6 ]
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 @printf(i8* %27, i8* %29)
ret i32 1
}