#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*/ err_sys(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int write(int, char *, int);
void respond(int sockfd) {
  int n;
  char buf[4096];
  char response[22] = "I hear ya for shizzle";
  memset(buf, 0, 4096);
  n = read(sockfd, buf, 4096);
  if (n > 0) {
    printf("%s\n", buf);
    if (write(sockfd, response, 22) > 22) {
      err_sys("write error");
    }
  }
  if (n < 0) {
    err_sys("respond: read error");
  }
}


x86 assembly (clang, -O0):
<respond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x1030(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x1028(%rbp)
mov    0xe90(%rip),%eax
mov    %eax,-0x1020(%rbp)
mov    0xe87(%rip),%ax
mov    %ax,-0x101c(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1209 <respond+0xb9>
lea    -0x1010(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x16,%edx
call   1040 <write@plt>
cmp    $0x16,%eax
jle    1204 <respond+0xb4>
lea    0xe1b(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1209 <respond+0xb9>
cmpl   $0x0,-0x8(%rbp)
jge    121f <respond+0xcf>
lea    0xe0c(%rip),%rdi
call   1030 <err_sys@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<respond>:
push   %r14
push   %rbx
sub    $0x1028,%rsp
mov    %edi,%ebx
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x656c7a7a696873,%rax
mov    %rax,0xe(%rsp)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    11cb <respond+0x7b>
lea    0xe72(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x16,%edx
call   1040 <write@plt>
cmp    $0x16,%eax
jle    11d9 <respond+0x89>
lea    0xe51(%rip),%rdi
jmp    11d4 <respond+0x84>
jns    11d9 <respond+0x89>
lea    0xe52(%rip),%rdi
call   1030 <err_sys@plt>
add    $0x1028,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.respond.response = [22 x i8] c"I hear ya for shizzle\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [12 x i8] c"write error\00"
@.str.2 = [20 x i8] c"respond: read error\00"
define void @respond(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca [22 x i8]
store i32 %0, i32* %2
%6 = bitcast [22 x i8]* %5 to i8*
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 4096)
%9 = load i32, i32* %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4096)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %1
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %2
%18 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 22)
%20 = icmp sgt i32 %19, 22
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
br label %24
24: ; preds = %23, %1
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
ret void
}

LLVM IR (-O2):
@__const.respond.response = [22 x i8] c"I hear ya for shizzle\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [12 x i8] c"write error\00"
@.str.2 = [20 x i8] c"respond: read error\00"
define void @respond(i32 %0) {
%2 = alloca [4096 x i8]
%3 = alloca [22 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %4, i32 0, i32 4096)
%7 = call i32 @read(i32 %0, i8* %4, i32 4096)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%11 = call i32 @write(i32 %0, i8* %5, i32 22)
%12 = icmp sgt i32 %11, 22
br i1 %12, label %15, label %18
13: ; preds = %1
%14 = icmp slt i32 %7, 0
br i1 %14, label %15, label %18
15: ; preds = %13, %9
%16 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %13 ]
%17 = call i32 @err_sys(i8* %16)
br label %18
18: ; preds = %15, %9, %13
ret void
}