#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
void *reader_thread(void *arg) {
  int fd = *((int *)arg);
  for (;;) {
    char buf[64];
    int len = read(fd, buf, sizeof(buf));
    if (len == 0) {
      fprintf(stderr, "whoops zero len!\n");
      exit(0);
    }
    write(1, buf, len);
  }
}


x86 assembly (clang, -O0):
<reader_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    118f <reader_thread+0x4f>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1155 <reader_thread+0x15>

x86 assembly (clang, -O2):
<reader_thread>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    (%rdi),%ebp
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x40,%edx
call   1040 <read@plt>
test   %eax,%eax
je     1182 <reader_thread+0x42>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
test   %eax,%eax
jne    1160 <reader_thread+0x20>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"whoops zero len!\0A\00"
define i8* @reader_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %3
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 64)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %9
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 @write(i32 1, i8* %20, i32 %21)
br label %9
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"whoops zero len!\0A\00"
define noalias i8* @reader_thread(i8* nocapture %0) {
%2 = alloca [64 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 64)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %12, %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %1, %12
%13 = phi i32 [ %15, %12 ], [ %6, %1 ]
%14 = call i32 @write(i32 1, i8* %5, i32 %13)
%15 = call i32 @read(i32 %4, i8* %5, i32 64)
%16 = icmp eq i32 %15, 0
br i1 %16, label %8, label %12
}