#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 atoi(char *);
int /*<<< orphan*/ cleanUpAndExit(int);
int /*<<< orphan*/ handleSocketClose();
int recvToBuffer(int);
void processExit(char *buf, unsigned long len) {
  int exitcode;
  int bytesToRead = ((2048) - 1 < len) ? (2048) - 1 : len;
  int bytesRead = recvToBuffer(bytesToRead);
  if (bytesRead < 0) {
    handleSocketClose();
  }
  buf[bytesRead] = 0;
  exitcode = atoi(buf);
  cleanUpAndExit(exitcode);
}


x86 assembly (clang, -O0):
<processExit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x7ff,%eax
cmp    -0x10(%rbp),%rax
jae    116d <processExit+0x2d>
mov    $0x7ff,%eax
mov    %rax,-0x28(%rbp)
jmp    1175 <processExit+0x35>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <recvToBuffer@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1198 <processExit+0x58>
mov    $0x0,%al
call   1050 <handleSocketClose@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <cleanUpAndExit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processExit>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x7ff,%rsi
mov    $0x7ff,%edi
cmovb  %esi,%edi
call   1040 <recvToBuffer@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1167 <processExit+0x27>
xor    %eax,%eax
call   1050 <handleSocketClose@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <cleanUpAndExit@plt>

LLVM IR (-O0):
define void @processExit(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = icmp ult i64 2047, %8
br i1 %9, label %10, label %11
10: ; preds = %2
br label %13
11: ; preds = %2
%12 = load i64, i64* %4
br label %13
13: ; preds = %11, %10
%14 = phi i64 [ 2047, %10 ], [ %12, %11 ]
%15 = trunc i64 %14 to i32
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @recvToBuffer(i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (...) @handleSocketClose()
br label %22
22: ; preds = %20, %13
%23 = load i8*, i8** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %3
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = call i32 @cleanUpAndExit(i32 %29)
ret void
}

LLVM IR (-O2):
define void @processExit(i8* nocapture %0, i64 %1) {
%3 = icmp ult i64 %1, 2047
%4 = select i1 %3, i64 %1, i64 2047
%5 = trunc i64 %4 to i32
%6 = tail call i32 @recvToBuffer(i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @handleSocketClose()
br label %10
10: ; preds = %8, %2
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
%13 = tail call i32 @atoi(i8* %0)
%14 = tail call i32 @cleanUpAndExit(i32 %13)
ret void
}