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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, int *, int);
void list_slaves(int sockfd) {
  int request_type = 20;
  int request = 23;
  write(sockfd, &request_type, sizeof(int));
  write(sockfd, &request, sizeof(request));
  char *response = (char *)malloc(1000);
  memset(response, 0, 1000);
  read(sockfd, response, 1000);
  printf("Active Slaves");
  printf("%s", response);
  printf("--------------------------------------------------------\n");
  free(response);
  printf("\nPress 'Enter' to return to the menu...");
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<list_slaves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
movl   $0x17,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    $0x3e8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x3e8,%edx
call   1070 <read@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_slaves>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x14,0x4(%rsp)
movl   $0x17,(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <write@plt>
mov    $0x3e8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1080 <read@plt>
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1090 <getchar@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Active Slaves\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [58 x i8] c"--------------------------------------------------------\0A\00"
@.str.3 = [40 x i8] c"\0APress 'Enter' to return to the menu...\00"
define void @list_slaves(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
store i32 20, i32* %3
store i32 23, i32* %4
%6 = load i32, i32* %2
%7 = call i32 @write(i32 %6, i32* %3, i32 4)
%8 = load i32, i32* %2
%9 = call i32 @write(i32 %8, i32* %4, i32 4)
%10 = call i64 @malloc(i32 1000)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @memset(i8* %12, i32 0, i32 1000)
%14 = load i32, i32* %2
%15 = load i8*, i8** %5
%16 = call i32 @read(i32 %14, i8* %15, i32 1000)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 (...) @getchar()
%25 = call i32 (...) @getchar()
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Active Slaves\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [40 x i8] c"\0APress 'Enter' to return to the menu...\00"
@str = [57 x i8] c"--------------------------------------------------------\00"
define void @list_slaves(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 20, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 23, i32* %3
%6 = call i32 @write(i32 %0, i32* %2, i32 4)
%7 = call i32 @write(i32 %0, i32* %3, i32 4)
%8 = tail call i64 @malloc(i32 1000)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @memset(i8* %9, i32 0, i32 1000)
%11 = tail call i32 @read(i32 %0, i8* %9, i32 1000)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @free(i8* %9)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 (...) @getchar()
%18 = tail call i32 (...) @getchar()
ret void
}