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


x86 assembly (clang, -O0):
<write_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    124e <write_msg+0xde>
mov    -0xc(%rbp),%esi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0x48,%esi
call   1050 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1090 <set_last_char@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x48,%edx
call   1030 <write@plt>
cmp    $0x48,%eax
je     123b <write_msg+0xcb>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x118(%rbp),%edi
mov    -0x114(%rbp),%edx
mov    %rax,%rcx
lea    0xdeb(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1240 <write_msg+0xd0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <write_msg+0x16>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
lea    0xe7b(%rip),%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    0x2e55(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x48,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1090 <set_last_char@plt>
mov    0x4(%r14),%edi
mov    %rbx,%rsi
mov    $0x48,%edx
call   1030 <write@plt>
cmp    $0x48,%eax
jne    1258 <write_msg+0xe8>
lea    0xe31(%rip),%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x48,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1090 <set_last_char@plt>
mov    0x4(%r14),%edi
mov    %rbx,%rsi
mov    $0x48,%edx
call   1030 <write@plt>
cmp    $0x48,%eax
jne    1258 <write_msg+0xe8>
lea    0xdef(%rip),%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x48,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1090 <set_last_char@plt>
mov    0x4(%r14),%edi
mov    %rbx,%rsi
mov    $0x48,%edx
call   1030 <write@plt>
cmp    $0x48,%eax
jne    1258 <write_msg+0xe8>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d79(%rip),%rax
mov    (%rax),%ebx
mov    0x2d68(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xd9b(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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