#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recvMessage(int, char *);
int sendMessage(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *requestWorkload(int socket, char *buf) {
  static char workload[50];
  memset(buf, 0, sizeof(buf));
  strcpy(buf + 1, "204");
  if (-1 == sendMessage(socket, buf, 4)) {
    if (-1 == sendMessage(socket, buf, 4))
      perror("send req. workload");
  }
  recvMessage(socket, buf);
  strcpy(workload, buf + 4);
  return workload;
}


x86 assembly (clang, -O0):
<requestWorkload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xe82(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <sendMessage@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11d4 <requestWorkload+0x84>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <sendMessage@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11cf <requestWorkload+0x7f>
lea    0xe3a(%rip),%rdi
call   1070 <perror@plt>
jmp    11d4 <requestWorkload+0x84>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <recvMessage@plt>
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
lea    0x2e71(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e65(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<requestWorkload>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    0x1(%rbx),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <sendMessage@plt>
cmp    $0xffffffff,%eax
jne    119f <requestWorkload+0x4f>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <sendMessage@plt>
cmp    $0xffffffff,%eax
je     11c9 <requestWorkload+0x79>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <recvMessage@plt>
add    $0x4,%rbx
lea    0x2eac(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
jmp    119f <requestWorkload+0x4f>

LLVM IR (-O0):
@requestWorkload.workload = internal global [50 x i8] zeroinitializer
@.str = [4 x i8] c"204\00"
@.str.1 = [19 x i8] c"send req. workload\00"
define i8* @requestWorkload(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i32 @memset(i8* %5, i32 0, i32 8)
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = load i8*, i8** %4
%12 = call i32 @sendMessage(i32 %10, i8* %11, i32 4)
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* %3
%16 = load i8*, i8** %4
%17 = call i32 @sendMessage(i32 %15, i8* %16, i32 4)
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
br label %22
22: ; preds = %21, %2
%23 = load i32, i32* %3
%24 = load i8*, i8** %4
%25 = call i32 @recvMessage(i32 %23, i8* %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = call i32 @strcpy(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @requestWorkload.workload, i64 0, i64 0), i8* %27)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @requestWorkload.workload, i64 0, i64 0)
}

LLVM IR (-O2):
@requestWorkload.workload = internal global [50 x i8] zeroinitializer
@.str = [4 x i8] c"204\00"
@.str.1 = [19 x i8] c"send req. workload\00"
define i8* @requestWorkload(i32 %0, i8* %1) {
%3 = tail call i32 @memset(i8* %1, i32 0, i32 8)
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @sendMessage(i32 %0, i8* %1, i32 4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = tail call i32 @sendMessage(i32 %0, i8* %1, i32 4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %8, %11, %2
%14 = tail call i32 @recvMessage(i32 %0, i8* %1)
%15 = getelementptr inbounds i8, i8* %1, i64 4
%16 = tail call i32 @strcpy(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @requestWorkload.workload, i64 0, i64 0), i8* %15)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @requestWorkload.workload, i64 0, i64 0)
}