#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*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, char *);
int readn(int, char *, int);
int /*<<< orphan*/ shutdown(int, int);
int /*<<< orphan*/ write(int, char *, int);
void *readAndWrite(void *temp) {
  int sock = *((int *)temp);
  char buf[256];
  char *p = buf;
  bzero(buf, 256);
  int n = readn(sock, p, 255);
  if (n > 0) {
    printf("%s \n", buf);
    write(sock, "I'v got your message", 20);
  }
  shutdown(sock, 2);
  close(sock);
}


x86 assembly (clang, -O0):
<readAndWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    -0x14(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    $0xff,%edx
call   1060 <readn@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jle    11e5 <readAndWrite+0x85>
lea    -0x120(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xe2a(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAndWrite>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    (%rdi),%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xff,%edx
call   1060 <readn@plt>
test   %eax,%eax
jle    11b1 <readAndWrite+0x51>
lea    0xe6a(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xe60(%rip),%rsi
mov    %ebx,%edi
mov    $0x14,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s \0A\00"
@.str.1 = [21 x i8] c"I'v got your message\00"
define i8* @readAndWrite(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %4
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8* %11, i8** %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = call i32 @bzero(i8* %12, i32 256)
%14 = load i32, i32* %4
%15 = load i8*, i8** %6
%16 = call i32 @readn(i32 %14, i8* %15, i32 255)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %1
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %24
24: ; preds = %19, %1
%25 = load i32, i32* %4
%26 = call i32 @shutdown(i32 %25, i32 2)
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s \0A\00"
@.str.1 = [21 x i8] c"I'v got your message\00"
define noalias i8* @readAndWrite(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 256)
%7 = call i32 @readn(i32 %4, i8* %5, i32 255)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5)
%11 = call i32 @write(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %12
12: ; preds = %9, %1
%13 = call i32 @shutdown(i32 %4, i32 2)
%14 = call i32 @close(i32 %4)
ret i8* undef
}