#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 errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ printf(char *, int, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
void read_msg(int fd[]) {
  int i;
  char buf[256];
  for (i = 0; i < 3; i++) {
    if (read(fd[0], buf, 72) <= 0) {
      fprintf(stderr, "Err.: %d read() %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
    printf("read - msg[%d] = %s\n", i, buf);
  }
}


x86 assembly (clang, -O0):
<read_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    120a <read_msg+0xba>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x48,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     11e6 <read_msg+0x96>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x118(%rbp),%edi
mov    -0x114(%rbp),%edx
mov    %rax,%rcx
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <read_msg+0x16>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_msg>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    %rsp,%rsi
mov    $0x48,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    11e1 <read_msg+0x91>
lea    0xe9d(%rip),%rdi
mov    %rsp,%rbp
xor    %esi,%esi
mov    %rbp,%rdx
call   1030 <printf@plt>
mov    (%rbx),%edi
mov    %rbp,%rsi
mov    $0x48,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    11e1 <read_msg+0x91>
lea    0xe75(%rip),%rdi
mov    %rsp,%rbp
mov    $0x1,%esi
mov    %rbp,%rdx
call   1030 <printf@plt>
mov    (%rbx),%edi
mov    %rbp,%rsi
mov    $0x48,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    11e1 <read_msg+0x91>
lea    0xe4a(%rip),%rdi
mov    %rsp,%rdx
mov    $0x2,%esi
call   1030 <printf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2df8(%rip),%rax
mov    (%rax),%ebx
mov    0x2de7(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xdff(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Err.: %d read() %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"read - msg[%d] = %s\0A\00"
define void @read_msg(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [256 x i8]
store i32* %0, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 72)
%14 = icmp sle i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %8
%24 = load i32, i32* %3
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %25)
br label %27
27: ; preds = %23
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %5
30: ; preds = %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Err.: %d read() %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"read - msg[%d] = %s\0A\00"
define void @read_msg(i32* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* %0
%5 = call i64 @read(i32 %4, i8* %3, i32 72)
%6 = icmp slt i64 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %19, %14, %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* %3)
%16 = load i32, i32* %0
%17 = call i64 @read(i32 %16, i8* %3, i32 72)
%18 = icmp slt i64 %17, 1
br i1 %18, label %7, label %19
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 1, i8* %3)
%21 = load i32, i32* %0
%22 = call i64 @read(i32 %21, i8* %3, i32 72)
%23 = icmp slt i64 %22, 1
br i1 %23, label %7, label %24
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 2, i8* %3)
ret void
}