#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*/ EXIT_FAILURE;
int /*<<< orphan*/ STDIN_FILENO;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int write(int, char *, int);
void write_strings(char b[], int fdw) {
  int i;
  int n_read;
  printf("Immettere il testo (digitare X per uscire)\n");
  for (i = 0; i < 128; i++)
    b[i] = 0;
  while ((n_read = read(STDIN_FILENO, b, 128)) > 0) {
    if (b[n_read - 2] == 'X')
      break;
    if (write(fdw, b, n_read) != n_read) {
      fprintf(stderr, "Err: (%d) - %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<write_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x80,-0x10(%rbp)
jge    11a9 <write_strings+0x49>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1182 <write_strings+0x22>
jmp    11ae <write_strings+0x4e>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1256 <write_strings+0xf6>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    11f0 <write_strings+0x90>
jmp    1256 <write_strings+0xf6>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     1251 <write_strings+0xf1>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xdee(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11ae <write_strings+0x4e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_strings>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movups %xmm0,(%rbx)
movups %xmm0,0x10(%rbx)
movups %xmm0,0x20(%rbx)
movups %xmm0,0x30(%rbx)
movups %xmm0,0x40(%rbx)
movups %xmm0,0x50(%rbx)
movups %xmm0,0x60(%rbx)
movups %xmm0,0x70(%rbx)
mov    0x2e26(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    121a <write_strings+0xba>
mov    %eax,%ebp
cltq
cmpb   $0x58,-0x2(%rax,%rbx,1)
je     121a <write_strings+0xba>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     11b0 <write_strings+0x50>
mov    0x2df9(%rip),%rax
mov    (%rax),%ebx
mov    0x2de8(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe00(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Immettere il testo (digitare X per uscire)\0A\00"
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Err: (%d) - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @write_strings(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %8
8: ; preds = %16, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 128
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %8
19: ; preds = %8
br label %20
20: ; preds = %50, %19
%21 = load i32, i32* @STDIN_FILENO
%22 = load i8*, i8** %3
%23 = call i32 @read(i32 %21, i8* %22, i32 128)
store i32 %23, i32* %6
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 88
br i1 %33, label %34, label %35
34: ; preds = %25
br label %51
35: ; preds = %25
%36 = load i32, i32* %4
%37 = load i8*, i8** %3
%38 = load i32, i32* %6
%39 = call i32 @write(i32 %36, i8* %37, i32 %38)
%40 = load i32, i32* %6
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %44, i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %35
br label %20
51: ; preds = %34, %20
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Err: (%d) - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [43 x i8] c"Immettere il testo (digitare X per uscire)\00"
define void @write_strings(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %2, %14
%5 = load i32, i32* @STDIN_FILENO
%6 = tail call i32 @read(i32 %5, i8* %0, i32 128)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %4
%9 = add nsw i32 %6, -2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 88
br i1 %13, label %24, label %14
14: ; preds = %8
%15 = tail call i32 @write(i32 %1, i8* %0, i32 %6)
%16 = icmp eq i32 %15, %6
br i1 %16, label %4, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %8, %4
ret void
}