#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(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
void *handler(void *arg) {
  int *p = (int *)arg;
  int fd = *p;
  int ret;
  char buff[1024];
  while (1) {
    memset(buff, 0, 1024);
    ret = read(fd, buff, 1024);
    printf("recv a message:%s\n", buff);
    if (strcmp(buff, "quit") == 0) {
      exit(0);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <handler+0x81>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    1170 <handler+0x20>

x86 assembly (clang, -O2):
<handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    (%rdi),%ebp
mov    %rsp,%rbx
lea    0xe97(%rip),%r14
lea    0xea3(%rip),%r15
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1170 <handler+0x20>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"recv a message:%s\0A\00"
@.str.1 = [5 x i8] c"quit\00"
define i8* @handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
store i32 %10, i32* %4
br label %11
11: ; preds = %1, %24
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 1024)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 1024)
store i32 %16, i32* %5
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %11
br label %11
}

LLVM IR (-O2):
@.str = [19 x i8] c"recv a message:%s\0A\00"
@.str.1 = [5 x i8] c"quit\00"
define noalias i8* @handler(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %6, %1
%7 = call i32 @memset(i8* %5, i32 0, i32 1024)
%8 = call i32 @read(i32 %4, i8* %5, i32 1024)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = call i32 @exit(i32 0)
unreachable
}