#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int do_read(int /*<<< orphan*/, unsigned char *, unsigned int);
scalar_t__ do_write(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ is_help_option(char *);
scalar_t__ output_line(int /*<<< orphan*/, char const *, unsigned int,
                       unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  const char *label;
  unsigned pos;
  switch (argc) {
  case 1:
    label = "";
    break;
  case 2:
    if (is_help_option(argv[1])) {
      usage();
      return EXIT_SUCCESS;
    } else
      label = argv[1];
    break;
  default:
    usage();
    return EXIT_FAILURE;
  }
  for (pos = 0;;) {
    unsigned char buf[16];
    unsigned left = 16 - (pos % 16);
    int res;
    res = do_read(STDIN_FILENO, buf, left);
    if (!res)
      return EXIT_SUCCESS;
    else if (res < 0) {
      fprintf(stderr, "%s: read error: %s\n", label, strerror(errno));
      return EXIT_FAILURE;
    }
    if (output_line(STDERR_FILENO, label, pos, buf, res) <= 0) {
      fprintf(stderr, "%s: write error on stderr: %s\n", label,
              strerror(errno));
      return EXIT_FAILURE;
    }
    if (do_write(STDOUT_FILENO, buf, res) < 0) {
      fprintf(stderr, "%s: write error: %s\n", label, strerror(errno));
      return EXIT_FAILURE;
    }
    pos += res;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x1,%eax
je     11ab <main+0x3b>
jmp    119a <main+0x2a>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
je     11bb <main+0x4b>
jmp    11fa <main+0x8a>
lea    0xe61(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1212 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <is_help_option@plt>
cmp    $0x0,%eax
je     11e9 <main+0x79>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1212 <main+0xa2>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
mov    $0x10,%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <do_read@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    125c <main+0xec>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
cmpl   $0x0,-0x38(%rbp)
jge    12af <main+0x13f>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd67(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
jmp    12b4 <main+0x144>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8d
call   1070 <output_line@plt>
cmp    $0x0,%rax
jg     1324 <main+0x1b4>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd06(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1040 <do_write@plt>
cmp    $0x0,%rax
jge    138c <main+0x21c>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcbd(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139a <main+0x22a>
mov    -0x38(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1219 <main+0xa9>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
je     11ab <main+0x3b>
cmp    $0x2,%edi
jne    11b4 <main+0x44>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <is_help_option@plt>
test   %eax,%eax
je     11c0 <main+0x50>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e12(%rip),%rax
jmp    12a4 <main+0x134>
lea    0xe61(%rip),%r15
jmp    11c4 <main+0x54>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    129d <main+0x12d>
mov    0x8(%rbx),%r15
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1030 <do_read@plt>
mov    %eax,%ebx
mov    0x2dd5(%rip),%rax
test   %ebx,%ebx
je     12a4 <main+0x134>
xor    %ebp,%ebp
mov    0x2dd4(%rip),%r14
mov    %rsp,%r12
mov    0x2df2(%rip),%r13
xchg   %ax,%ax
test   %ebx,%ebx
js     125d <main+0xed>
mov    (%r14),%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
mov    %ebx,%r8d
call   1070 <output_line@plt>
test   %rax,%rax
jle    1266 <main+0xf6>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <do_write@plt>
test   %rax,%rax
js     126f <main+0xff>
add    %ebx,%ebp
mov    %ebp,%eax
and    $0xf,%eax
mov    $0x10,%edx
sub    %eax,%edx
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1030 <do_read@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1200 <main+0x90>
mov    0x2d5d(%rip),%rax
jmp    12a4 <main+0x134>
lea    0xd9c(%rip),%rbp
jmp    1276 <main+0x106>
lea    0xda7(%rip),%rbp
jmp    1276 <main+0x106>
lea    0xdbd(%rip),%rbp
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"%s: read error: %s\0A\00"
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str.2 = [31 x i8] c"%s: write error on stderr: %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [21 x i8] c"%s: write error: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
switch i32 %11, label %27 [
i32 1, label %12
i32 2, label %13
]
12: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %30
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @is_help_option(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 (...) @usage()
%21 = load i32, i32* @EXIT_SUCCESS
store i32 %21, i32* %3
br label %86
22: ; preds = %13
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %6
br label %26
26: ; preds = %22
br label %30
27: ; preds = %2
%28 = call i32 (...) @usage()
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %86
30: ; preds = %26, %12
store i32 0, i32* %7
br label %31
31: ; preds = %82, %30
%32 = load i32, i32* %7
%33 = urem i32 %32, 16
%34 = sub i32 16, %33
store i32 %34, i32* %9
%35 = load i32, i32* @STDIN_FILENO
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* %9
%38 = call i32 @do_read(i32 %35, i8* %36, i32 %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %31
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %86
43: ; preds = %31
%44 = load i32, i32* %10
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %6
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %48, i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
store i32 %52, i32* %3
br label %86
53: ; preds = %43
br label %54
54: ; preds = %53
%55 = load i32, i32* @STDERR_FILENO
%56 = load i8*, i8** %6
%57 = load i32, i32* %7
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%59 = load i32, i32* %10
%60 = call i64 @output_line(i32 %55, i8* %56, i32 %57, i8* %58, i32 %59)
%61 = icmp sle i64 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %54
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %6
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %64, i8* %66)
%68 = load i32, i32* @EXIT_FAILURE
store i32 %68, i32* %3
br label %86
69: ; preds = %54
%70 = load i32, i32* @STDOUT_FILENO
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%72 = load i32, i32* %10
%73 = call i64 @do_write(i32 %70, i8* %71, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %82
75: ; preds = %69
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %6
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %77, i8* %79)
%81 = load i32, i32* @EXIT_FAILURE
store i32 %81, i32* %3
br label %86
82: ; preds = %69
%83 = load i32, i32* %10
%84 = load i32, i32* %7
%85 = add i32 %84, %83
store i32 %85, i32* %7
br label %31
86: ; preds = %75, %62, %46, %41, %27, %19
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"%s: read error: %s\0A\00"
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str.2 = [31 x i8] c"%s: write error on stderr: %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [21 x i8] c"%s: write error: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
switch i32 %0, label %14 [
i32 1, label %17
i32 2, label %4
]
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @is_help_option(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 (...) @usage()
%11 = load i32, i32* @EXIT_SUCCESS
br label %51
12: ; preds = %4
%13 = load i8*, i8** %5
br label %17
14: ; preds = %2
%15 = tail call i32 (...) @usage()
%16 = load i32, i32* @EXIT_FAILURE
br label %51
17: ; preds = %2, %12
%18 = phi i8* [ %13, %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @do_read(i32 %20, i8* %19, i32 16)
%22 = icmp eq i32 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %17, %44
%24 = phi i32 [ %49, %44 ], [ %21, %17 ]
%25 = phi i32 [ %45, %44 ], [ 0, %17 ]
%26 = icmp slt i32 %24, 0
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i32, i32* @STDERR_FILENO
%29 = call i64 @output_line(i32 %28, i8* %18, i32 %25, i8* %19, i32 %24)
%30 = icmp slt i64 %29, 1
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* @STDOUT_FILENO
%33 = call i64 @do_write(i32 %32, i8* %19, i32 %24)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31, %27, %23
%36 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %23 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), %27 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %31 ]
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* %36, i8* %18, i8* %39)
br label %41
41: ; preds = %44, %35, %17
%42 = phi i32* [ @EXIT_SUCCESS, %17 ], [ @EXIT_FAILURE, %35 ], [ @EXIT_SUCCESS, %44 ]
%43 = load i32, i32* %42
br label %51
44: ; preds = %31
%45 = add i32 %24, %25
%46 = and i32 %45, 15
%47 = sub nuw nsw i32 16, %46
%48 = load i32, i32* @STDIN_FILENO
%49 = call i32 @do_read(i32 %48, i8* %19, i32 %47)
%50 = icmp eq i32 %49, 0
br i1 %50, label %41, label %23
51: ; preds = %41, %14, %9
%52 = phi i32 [ %16, %14 ], [ %11, %9 ], [ %43, %41 ]
ret i32 %52
}