#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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ putchar(char);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ s_cmd(int, char *);
int /*<<< orphan*/ s_err(char *);
int /*<<< orphan*/ s_log(char *);
int /*<<< orphan*/ s_prt(char *, size_t);
int Session(int conn_fd, int bytes) {
  char buff[4096];
  size_t length = 0;
  bzero(buff, sizeof(buff));
  if ((length = recv(conn_fd, buff, bytes, 0)) < 0)
    s_err("recv data");
  if (buff[length - 1] == '\n')
    buff[--length] = '\0';
  if (buff[length - 1] == '\r')
    buff[--length] = '\0';
  s_log("MSG");
  s_prt(buff, length);
  putchar('\n');
  s_cmd(conn_fd, buff);
  return 0;
}


x86 assembly (clang, -O0):
<Session>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x8(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
jae    11ce <Session+0x5e>
lea    0xe37(%rip),%rdi
call   1090 <s_err@plt>
mov    -0x1018(%rbp),%rax
sub    $0x1,%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1207 <Session+0x97>
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x1018(%rbp)
movb   $0x0,-0x1011(%rbp,%rax,1)
mov    -0x1018(%rbp),%rax
sub    $0x1,%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    1240 <Session+0xd0>
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x1018(%rbp)
movb   $0x0,-0x1011(%rbp,%rax,1)
lea    0xdc3(%rip),%rdi
call   1060 <s_log@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rsi
call   1050 <s_prt@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
call   1070 <s_cmd@plt>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Session>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1080 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x1(%rax),%rbx
mov    -0x1(%rsp,%rax,1),%dl
cmp    $0xa,%dl
jne    11b3 <Session+0x53>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %rax,%rcx
add    $0xfffffffffffffffe,%rcx
mov    -0x2(%rsp,%rax,1),%dl
cmp    $0xd,%dl
je     11be <Session+0x5e>
jmp    11c5 <Session+0x65>
mov    %rbx,%rcx
mov    %rax,%rbx
cmp    $0xd,%dl
jne    11c5 <Session+0x65>
movb   $0x0,(%rsp,%rcx,1)
mov    %rcx,%rbx
lea    0xe34(%rip),%rdi
call   1060 <s_log@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <s_prt@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1070 <s_cmd@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"recv data\00"
@.str.1 = [4 x i8] c"MSG\00"
define i32 @Session(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i64 0, i64* %6
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = call i32 @bzero(i8* %7, i32 4096)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i64 @recv(i32 %9, i8* %10, i32 %11, i32 0)
store i64 %12, i64* %6
%13 = icmp ult i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @s_err(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i64, i64* %6
%18 = sub i64 %17, 1
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i64, i64* %6
%25 = add i64 %24, -1
store i64 %25, i64* %6
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %23, %16
%28 = load i64, i64* %6
%29 = sub i64 %28, 1
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 13
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i64, i64* %6
%36 = add i64 %35, -1
store i64 %36, i64* %6
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %34, %27
%39 = call i32 @s_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%41 = load i64, i64* %6
%42 = call i32 @s_prt(i8* %40, i64 %41)
%43 = call i32 @putchar(i8 signext 10)
%44 = load i32, i32* %3
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%46 = call i32 @s_cmd(i32 %44, i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"MSG\00"
define i32 @Session(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 4096)
%6 = call i64 @recv(i32 %0, i8* %4, i32 %1, i32 0)
%7 = add i64 %6, -1
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %2
store i8 0, i8* %8
%12 = add i64 %6, -2
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %12
%14 = load i8, i8* %13
br label %15
15: ; preds = %11, %2
%16 = phi i8 [ %14, %11 ], [ %9, %2 ]
%17 = phi i64 [ %12, %11 ], [ %7, %2 ]
%18 = phi i64 [ %7, %11 ], [ %6, %2 ]
%19 = icmp eq i8 %16, 13
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %21
br label %22
22: ; preds = %20, %15
%23 = phi i64 [ %17, %20 ], [ %18, %15 ]
%24 = call i32 @s_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @s_prt(i8* %4, i64 %23)
%26 = call i32 @putchar(i8 signext 10)
%27 = call i32 @s_cmd(i32 %0, i8* %4)
ret i32 0
}