#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 */
scalar_t__ Read(int, char *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_detach(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_self();
void *routine(void *arg) {
  pthread_detach(pthread_self());
  int fd = *((int *)arg);
  char *msg = malloc(1024);
  while (1) {
    bzero(msg, 1024);
    if (Read(fd, msg, 1024) == 0) {
      printf("server has been shutdown, bye-bye!\n");
      break;
    }
    printf("from server: %s", msg);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
call   1060 <pthread_detach@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1080 <bzero@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1030 <Read@plt>
cmp    $0x0,%rax
jne    11dd <routine+0x6d>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f4 <routine+0x84>
mov    -0x18(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a1 <routine+0x31>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<routine>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <pthread_self@plt>
mov    %eax,%edi
call   1070 <pthread_detach@plt>
mov    (%rbx),%ebp
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x400,%esi
call   1090 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <Read@plt>
test   %rax,%rax
je     11fe <routine+0x7e>
lea    0xe34(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <Read@plt>
test   %rax,%rax
jne    11d0 <routine+0x50>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"server has been shutdown, bye-bye!\0A\00"
@.str.1 = [16 x i8] c"from server: %s\00"
define i8* @routine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
%6 = call i32 @pthread_detach(i32 %5)
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %3
%10 = call i8* @malloc(i32 1024)
store i8* %10, i8** %4
br label %11
11: ; preds = %1, %20
%12 = load i8*, i8** %4
%13 = call i32 @bzero(i8* %12, i32 1024)
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = call i64 @Read(i32 %14, i8* %15, i32 1024)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %23
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %11
23: ; preds = %18
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"from server: %s\00"
@str = [35 x i8] c"server has been shutdown, bye-bye!\00"
define noalias i8* @routine(i8* nocapture %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @pthread_detach(i32 %2)
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%7 = tail call i32 @bzero(i8* %6, i32 1024)
%8 = tail call i64 @Read(i32 %5, i8* %6, i32 1024)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %13, %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %1, %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = tail call i32 @bzero(i8* %6, i32 1024)
%16 = tail call i64 @Read(i32 %5, i8* %6, i32 1024)
%17 = icmp eq i64 %16, 0
br i1 %17, label %10, label %13
}