#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int main() {
  char *dev = "/dev/ms0\0";
  char *s = "ciao\0";
  printf("start %s\n", dev);
  int fd = open(dev, O_RDWR);
  if (fd < 0) {
    printf("%s - err open\n", dev);
    return -1;
  }
  char data[100];
  int ret;
  int l = (int)strlen(s);
  ioctl(fd, 3, 3);
  ioctl(fd, 1, 5);
  ioctl(fd, 5, 0);
  ioctl(fd, 4, 0);
  ioctl(fd, 3, 3);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c3 <main+0x73>
mov    -0x10(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x88(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x3,%edx
mov    %edx,%esi
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
mov    $0x5,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x3,%edx
mov    %edx,%esi
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec0(%rip),%rdi
lea    0xeaf(%rip),%rbx
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11ca <main+0x8a>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x3,%esi
mov    $0x3,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <ioctl@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
mov    $0x3,%esi
mov    $0x3,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    11e2 <main+0xa2>
lea    0xe43(%rip),%rdi
lea    0xe28(%rip),%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/ms0\00\00"
@.str.1 = [6 x i8] c"ciao\00\00"
@.str.2 = [10 x i8] c"start %s\0A\00"
@O_RDWR = global i32 0
@.str.3 = [15 x i8] c"%s - err open\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %3
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %16)
store i32 -1, i32* %1
br label %34
18: ; preds = %0
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %7
%22 = load i32, i32* %4
%23 = call i32 @ioctl(i32 %22, i32 3, i32 3)
%24 = load i32, i32* %4
%25 = call i32 @ioctl(i32 %24, i32 1, i32 5)
%26 = load i32, i32* %4
%27 = call i32 @ioctl(i32 %26, i32 5, i32 0)
%28 = load i32, i32* %4
%29 = call i32 @ioctl(i32 %28, i32 4, i32 0)
%30 = load i32, i32* %4
%31 = call i32 @ioctl(i32 %30, i32 3, i32 3)
%32 = load i32, i32* %4
%33 = call i32 @close(i32 %32)
store i32 0, i32* %1
br label %34
34: ; preds = %18, %15
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/ms0\00\00"
@.str.2 = [10 x i8] c"start %s\0A\00"
@O_RDWR = global i32 0
@.str.3 = [15 x i8] c"%s - err open\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = tail call i32 @ioctl(i32 %3, i32 3, i32 3)
%9 = tail call i32 @ioctl(i32 %3, i32 1, i32 5)
%10 = tail call i32 @ioctl(i32 %3, i32 5, i32 0)
%11 = tail call i32 @ioctl(i32 %3, i32 4, i32 0)
%12 = tail call i32 @ioctl(i32 %3, i32 3, i32 3)
%13 = tail call i32 @close(i32 %3)
br label %14
14: ; preds = %7, %5
%15 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %15
}