#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*/ BUFSIZ;
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ write(int, char *, int);
int TCPechod(int sock) {
  char buf[BUFSIZ + 1];
  int cc;
  printf("***** TCPechod(%d) called\n", sock);
  while ((cc = read(sock, buf, sizeof(buf))) > 0) {
    buf[cc] = 0;
    printf("***** TCPechod(%d): received %d bytes: `%s`\n", sock, cc, buf);
    if (write(sock, buf, cc) < 0)
      return -1;
  }
  if (cc < 0)
    return -1;
  sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<TCPechod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%edi
mov    %eax,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11fe <TCPechod+0xbe>
mov    -0x28(%rbp),%rcx
movslq -0x1c(%rbp),%rax
movb   $0x0,(%rcx,%rax,1)
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11f9 <TCPechod+0xb9>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1233 <TCPechod+0xf3>
jmp    118f <TCPechod+0x4f>
cmpl   $0x0,-0x1c(%rbp)
jge    121b <TCPechod+0xdb>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1233 <TCPechod+0xf3>
mov    $0xa,%edi
call   1060 <sleep@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TCPechod>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
mov    0x2e88(%rip),%rax
mov    (%rax),%r14d
add    $0x1,%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe89(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe93(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11d2 <TCPechod+0x92>
mov    %eax,%ebx
mov    %eax,%eax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1190 <TCPechod+0x50>
jmp    11e2 <TCPechod+0xa2>
js     11e2 <TCPechod+0xa2>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
jmp    11e7 <TCPechod+0xa7>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [27 x i8] c"***** TCPechod(%d) called\0A\00"
@.str.1 = [45 x i8] c"***** TCPechod(%d): received %d bytes: `%s`\0A\00"
define i32 @TCPechod(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* @BUFSIZ
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i32, i32* %3
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %32, %1
%16 = load i32, i32* %3
%17 = trunc i64 %10 to i32
%18 = call i32 @read(i32 %16, i8* %12, i32 %17)
store i32 %18, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %12, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %3
%25 = load i32, i32* %6
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i8* %12)
%27 = load i32, i32* %3
%28 = load i32, i32* %6
%29 = call i64 @write(i32 %27, i8* %12, i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %20
store i32 -1, i32* %2
store i32 1, i32* %7
br label %39
32: ; preds = %20
br label %15
33: ; preds = %15
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -1, i32* %2
store i32 1, i32* %7
br label %39
37: ; preds = %33
%38 = call i32 @sleep(i32 10)
store i32 0, i32* %2
store i32 1, i32* %7
br label %39
39: ; preds = %37, %36, %31
%40 = load i8*, i8** %4
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [27 x i8] c"***** TCPechod(%d) called\0A\00"
@.str.1 = [45 x i8] c"***** TCPechod(%d): received %d bytes: `%s`\0A\00"
define i32 @TCPechod(i32 %0) {
%2 = load i32, i32* @BUFSIZ
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %7
7: ; preds = %10, %1
%8 = call i32 @read(i32 %0, i8* %5, i32 %3)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %8, i8* %5)
%14 = call i64 @write(i32 %0, i8* %5, i32 %8)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %7
16: ; preds = %7
%17 = icmp slt i32 %8, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = call i32 @sleep(i32 10)
br label %20
20: ; preds = %10, %16, %18
%21 = phi i32 [ 0, %18 ], [ -1, %16 ], [ -1, %10 ]
ret i32 %21
}