#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
scalar_t__ forkpty(int *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int send(int, char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ write(int, char *, int);
void handle_client(int sockfd) {
  const char *hello_msg = "<rembash2>\n";
  int hello_len = strlen(hello_msg);
  int bytes_sent = send(sockfd, hello_msg, hello_len, 0);
  if (bytes_sent == -1 || bytes_sent != hello_len) {
    perror("send hello_msg");
    return;
  }
  char shared_key[256];
  int nbytes = recv(sockfd, shared_key, 255, 0);
  shared_key[nbytes - 1] = '\0';
  printf("Received %s from [%d]\n", shared_key, sockfd);
  if (strcmp(shared_key, "<cs591secret>") != 0) {
    printf("Shared key check failed for [%d]\n", sockfd);
    return;
  }
  const char *ok_msg = "<ok>\n";
  send(sockfd, ok_msg, strlen(ok_msg), 0);
  int master;
  pid_t pid;
  signal(SIGCHLD, SIG_IGN);
  pid = forkpty(&master, NULL, NULL, NULL);
  if (pid < 0) {
    const char *error_msg = "forkpty failed\n";
    perror(error_msg);
    send(sockfd, error_msg, strlen(error_msg), 0);
    return;
  }
  if (pid == 0) {
    execl("/bin/bash", "bash", NULL);
  } else {
    const char *ready_msg = "<ready>\n";
    send(sockfd, ready_msg, strlen(ready_msg), 0);
    int maxfd = master > sockfd ? master : sockfd;
    for (;;) {
      char buf[64 * 1024];
      fd_set readfds;
      FD_ZERO(&readfds);
      FD_SET(master, &readfds);
      FD_SET(sockfd, &readfds);
      if (select(maxfd + 1, &readfds, NULL, NULL, NULL) == -1) {
        perror("select");
        return;
      }
      if (FD_ISSET(master, &readfds)) {
        nbytes = read(master, buf, 64 * 1024);
        if (nbytes < 1) {
          break;
        }
        send(sockfd, buf, nbytes, 0);
      }
      if (FD_ISSET(sockfd, &readfds)) {
        nbytes = recv(sockfd, buf, 64 * 1024, 0);
        if (nbytes < 1) {
          break;
        }
        write(master, buf, nbytes);
      }
    }
  }
}


x86 assembly (clang, -O0):
<handle_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x101a0,%rsp
mov    %edi,-0x4(%rbp)
lea    0xdfb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     123f <handle_client+0x4f>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1250 <handle_client+0x60>
lea    0xdc6(%rip),%rdi
call   10f0 <perror@plt>
jmp    1583 <handle_client+0x393>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x120(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     12ca <handle_client+0xda>
mov    -0x4(%rbp),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1583 <handle_client+0x393>
lea    0xd91(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10174(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x10170(%rbp)
mov    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x10174(%rbp),%edi
mov    -0x10170(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    0x2cbf(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
lea    -0x134(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   10e0 <forkpty@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x140(%rbp)
jge    13ab <handle_client+0x1bb>
lea    0xd0e(%rip),%rax
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rdi
call   10f0 <perror@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10184(%rbp)
mov    -0x148(%rbp),%rax
mov    %rax,-0x10180(%rbp)
mov    -0x148(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x10184(%rbp),%edi
mov    -0x10180(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1583 <handle_client+0x393>
cmpq   $0x0,-0x140(%rbp)
jne    13d5 <handle_client+0x1e5>
lea    0xcb8(%rip),%rdi
lea    0xcb6(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1100 <execl@plt>
jmp    1583 <handle_client+0x393>
lea    0xca6(%rip),%rax
mov    %rax,-0x150(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10194(%rbp)
mov    -0x150(%rbp),%rax
mov    %rax,-0x10190(%rbp)
mov    -0x150(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x10194(%rbp),%edi
mov    -0x10190(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x134(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    143c <handle_client+0x24c>
mov    -0x134(%rbp),%eax
mov    %eax,-0x10198(%rbp)
jmp    1445 <handle_client+0x255>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10198(%rbp)
mov    -0x10198(%rbp),%eax
mov    %eax,-0x154(%rbp)
lea    -0x10164(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x134(%rbp),%edi
lea    -0x10164(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x4(%rbp),%edi
lea    -0x10164(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x154(%rbp),%edi
add    $0x1,%edi
lea    -0x10164(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
jne    14b8 <handle_client+0x2c8>
lea    0xbdd(%rip),%rdi
call   10f0 <perror@plt>
jmp    1583 <handle_client+0x393>
mov    -0x134(%rbp),%edi
lea    -0x10164(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     151a <handle_client+0x32a>
mov    -0x134(%rbp),%edi
lea    -0x10160(%rbp),%rsi
mov    $0x10000,%edx
call   1090 <read@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
jge    1503 <handle_client+0x313>
jmp    157e <handle_client+0x38e>
mov    -0x4(%rbp),%edi
lea    -0x10160(%rbp),%rsi
mov    -0x124(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x4(%rbp),%edi
lea    -0x10164(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1579 <handle_client+0x389>
mov    -0x4(%rbp),%edi
lea    -0x10160(%rbp),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
jge    1561 <handle_client+0x371>
jmp    157e <handle_client+0x38e>
mov    -0x134(%rbp),%edi
lea    -0x10160(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1040 <write@plt>
jmp    1451 <handle_client+0x261>
jmp    1583 <handle_client+0x393>
add    $0x101a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10118,%rsp
mov    %edi,%ebx
lea    0xdfa(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     13e6 <handle_client+0x1f6>
cmp    %ebp,%eax
jne    13e6 <handle_client+0x1f6>
lea    0x10(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
lea    0xdc8(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdcc(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1291 <handle_client+0xa1>
lea    0xdc6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x10118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdca(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10e0 <forkpty@plt>
test   %rax,%rax
js     13ff <handle_client+0x20f>
je     13cc <handle_client+0x1dc>
lea    0xd97(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x8(%rsp),%r14d
cmp    %ebx,%r14d
cmovle %ebx,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbp
lea    0x110(%rsp),%r15
xchg   %ax,%ax
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
cmp    $0xffffffff,%eax
je     1429 <handle_client+0x239>
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1391 <handle_client+0x1a1>
mov    0x8(%rsp),%edi
mov    %r15,%rsi
mov    $0x10000,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1283 <handle_client+0x93>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1320 <handle_client+0x130>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1283 <handle_client+0x93>
mov    0x8(%rsp),%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1320 <handle_client+0x130>
lea    0xca5(%rip),%rdi
lea    0xca3(%rip),%rsi
xor    %edx,%edx
call   1100 <execl@plt>
jmp    1283 <handle_client+0x93>
lea    0xc1f(%rip),%rdi
add    $0x10118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10f0 <perror@plt>
lea    0xc62(%rip),%rbp
mov    %rbp,%rdi
call   10f0 <perror@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1283 <handle_client+0x93>
lea    0xc5b(%rip),%rdi
call   10f0 <perror@plt>
jmp    1283 <handle_client+0x93>

LLVM IR (-O0):
@.str = [12 x i8] c"<rembash2>\0A\00"
@.str.1 = [15 x i8] c"send hello_msg\00"
@.str.2 = [23 x i8] c"Received %s from [%d]\0A\00"
@.str.3 = [14 x i8] c"<cs591secret>\00"
@.str.4 = [34 x i8] c"Shared key check failed for [%d]\0A\00"
@.str.5 = [6 x i8] c"<ok>\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str.6 = [16 x i8] c"forkpty failed\0A\00"
@.str.7 = [10 x i8] c"/bin/bash\00"
@.str.8 = [5 x i8] c"bash\00"
@.str.9 = [9 x i8] c"<ready>\0A\00"
@.str.10 = [7 x i8] c"select\00"
define void @handle_client(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [65536 x i8]
%15 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %2
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @send(i32 %18, i8* %19, i32 %20, i32 0)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, -1
br i1 %23, label %28, label %24
24: ; preds = %1
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24, %1
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %133
30: ; preds = %24
%31 = load i32, i32* %2
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%33 = call i32 @recv(i32 %31, i8* %32, i32 255, i32 0)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %39)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %30
%45 = load i32, i32* %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %133
47: ; preds = %30
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %8
%48 = load i32, i32* %2
%49 = load i8*, i8** %8
%50 = load i8*, i8** %8
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @send(i32 %48, i8* %49, i32 %51, i32 0)
%53 = load i32, i32* @SIGCHLD
%54 = load i32, i32* @SIG_IGN
%55 = call i32 @signal(i32 %53, i32 %54)
%56 = call i64 @forkpty(i32* %9, i32* null, i32* null, i32* null)
store i64 %56, i64* %10
%57 = load i64, i64* %10
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %47
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %11
%60 = load i8*, i8** %11
%61 = call i32 @perror(i8* %60)
%62 = load i32, i32* %2
%63 = load i8*, i8** %11
%64 = load i8*, i8** %11
%65 = call i32 @strlen(i8* %64)
%66 = call i32 @send(i32 %62, i8* %63, i32 %65, i32 0)
br label %133
67: ; preds = %47
%68 = load i64, i64* %10
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* null)
br label %133
72: ; preds = %67
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8** %12
%73 = load i32, i32* %2
%74 = load i8*, i8** %12
%75 = load i8*, i8** %12
%76 = call i32 @strlen(i8* %75)
%77 = call i32 @send(i32 %73, i8* %74, i32 %76, i32 0)
%78 = load i32, i32* %9
%79 = load i32, i32* %2
%80 = icmp sgt i32 %78, %79
br i1 %80, label %81, label %83
81: ; preds = %72
%82 = load i32, i32* %9
br label %85
83: ; preds = %72
%84 = load i32, i32* %2
br label %85
85: ; preds = %83, %81
%86 = phi i32 [ %82, %81 ], [ %84, %83 ]
store i32 %86, i32* %13
br label %87
87: ; preds = %131, %85
%88 = call i32 @FD_ZERO(i32* %15)
%89 = load i32, i32* %9
%90 = call i32 @FD_SET(i32 %89, i32* %15)
%91 = load i32, i32* %2
%92 = call i32 @FD_SET(i32 %91, i32* %15)
%93 = load i32, i32* %13
%94 = add nsw i32 %93, 1
%95 = call i32 @select(i32 %94, i32* %15, i32* null, i32* null, i32* null)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %99
97: ; preds = %87
%98 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
br label %133
99: ; preds = %87
%100 = load i32, i32* %9
%101 = call i64 @FD_ISSET(i32 %100, i32* %15)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %115
103: ; preds = %99
%104 = load i32, i32* %9
%105 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%106 = call i32 @read(i32 %104, i8* %105, i32 65536)
store i32 %106, i32* %7
%107 = load i32, i32* %7
%108 = icmp slt i32 %107, 1
br i1 %108, label %109, label %110
109: ; preds = %103
br label %132
110: ; preds = %103
%111 = load i32, i32* %2
%112 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%113 = load i32, i32* %7
%114 = call i32 @send(i32 %111, i8* %112, i32 %113, i32 0)
br label %115
115: ; preds = %110, %99
%116 = load i32, i32* %2
%117 = call i64 @FD_ISSET(i32 %116, i32* %15)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %131
119: ; preds = %115
%120 = load i32, i32* %2
%121 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%122 = call i32 @recv(i32 %120, i8* %121, i32 65536, i32 0)
store i32 %122, i32* %7
%123 = load i32, i32* %7
%124 = icmp slt i32 %123, 1
br i1 %124, label %125, label %126
125: ; preds = %119
br label %132
126: ; preds = %119
%127 = load i32, i32* %9
%128 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%129 = load i32, i32* %7
%130 = call i32 @write(i32 %127, i8* %128, i32 %129)
br label %131
131: ; preds = %126, %115
br label %87
132: ; preds = %125, %109
br label %133
133: ; preds = %28, %44, %59, %97, %132, %70
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"<rembash2>\0A\00"
@.str.1 = [15 x i8] c"send hello_msg\00"
@.str.2 = [23 x i8] c"Received %s from [%d]\0A\00"
@.str.3 = [14 x i8] c"<cs591secret>\00"
@.str.4 = [34 x i8] c"Shared key check failed for [%d]\0A\00"
@.str.5 = [6 x i8] c"<ok>\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str.6 = [16 x i8] c"forkpty failed\0A\00"
@.str.7 = [10 x i8] c"/bin/bash\00"
@.str.8 = [5 x i8] c"bash\00"
@.str.9 = [9 x i8] c"<ready>\0A\00"
@.str.10 = [7 x i8] c"select\00"
define void @handle_client(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [65536 x i8]
%5 = alloca i32
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = icmp ne i32 %7, -1
%9 = icmp eq i32 %7, %6
%10 = and i1 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %82
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 @recv(i32 %0, i8* %14, i32 255, i32 0)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %0)
%20 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %81
24: ; preds = %13
%25 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @send(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 0)
%27 = bitcast i32* %3 to i8*
%28 = load i32, i32* @SIGCHLD
%29 = load i32, i32* @SIG_IGN
%30 = call i32 @signal(i32 %28, i32 %29)
%31 = call i64 @forkpty(i32* %3, i32* null, i32* null, i32* null)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%35 = call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @send(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %35, i32 0)
br label %80
37: ; preds = %24
%38 = icmp eq i64 %31, 0
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32* null)
br label %80
41: ; preds = %37
%42 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%43 = call i32 @send(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %42, i32 0)
%44 = load i32, i32* %3
%45 = icmp sgt i32 %44, %0
%46 = select i1 %45, i32 %44, i32 %0
%47 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%48 = bitcast i32* %5 to i8*
%49 = add nsw i32 %46, 1
br label %50
50: ; preds = %79, %41
%51 = call i32 @FD_ZERO(i32* %5)
%52 = load i32, i32* %3
%53 = call i32 @FD_SET(i32 %52, i32* %5)
%54 = call i32 @FD_SET(i32 %0, i32* %5)
%55 = call i32 @select(i32 %49, i32* %5, i32* null, i32* null, i32* null)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
br label %78
59: ; preds = %50
%60 = load i32, i32* %3
%61 = call i64 @FD_ISSET(i32 %60, i32* %5)
%62 = icmp eq i64 %61, 0
br i1 %62, label %69, label %63
63: ; preds = %59
%64 = load i32, i32* %3
%65 = call i32 @read(i32 %64, i8* %47, i32 65536)
%66 = icmp slt i32 %65, 1
br i1 %66, label %78, label %67
67: ; preds = %63
%68 = call i32 @send(i32 %0, i8* %47, i32 %65, i32 0)
br label %69
69: ; preds = %67, %59
%70 = call i64 @FD_ISSET(i32 %0, i32* %5)
%71 = icmp eq i64 %70, 0
br i1 %71, label %79, label %72
72: ; preds = %69
%73 = call i32 @recv(i32 %0, i8* %47, i32 65536, i32 0)
%74 = icmp slt i32 %73, 1
br i1 %74, label %78, label %75
75: ; preds = %72
%76 = load i32, i32* %3
%77 = call i32 @write(i32 %76, i8* %47, i32 %73)
br label %79
78: ; preds = %63, %72, %57
br label %80
79: ; preds = %69, %75
br label %50
80: ; preds = %78, %39, %33
br label %81
81: ; preds = %80, %22
br label %82
82: ; preds = %81, %11
ret void
}