#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *read_some(int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
char *return_service_requested(int connfd, char *msg) {
  assert(msg != NULL);
  if (1)
    printf("[DEBUG] Sending message: %s\n", msg);
  if (!write(connfd, msg, strlen(msg) + 1)) {
    printf("[ERROR] Write failed.\n");
    return NULL;
  }
  if (1)
    printf("[DEBUG] Awaiting response...\n");
  return read_some(connfd);
}


x86 assembly (clang, -O0):
<return_service_requested>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
cmp    $0x0,%eax
jne    11d1 <return_service_requested+0x81>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11eb <return_service_requested+0x9b>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <read_some@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<return_service_requested>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1070 <assert@plt>
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
test   %eax,%eax
je     11ba <return_service_requested+0x5a>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <read_some@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"[DEBUG] Sending message: %s\0A\00"
@.str.1 = [23 x i8] c"[ERROR] Write failed.\0A\00"
@.str.2 = [30 x i8] c"[DEBUG] Awaiting response...\0A\00"
define i8* @return_service_requested(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i32 @write(i32 %12, i8* %13, i64 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %25
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = call i8* @read_some(i32 %23)
store i8* %24, i8** %3
br label %25
25: ; preds = %21, %19
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [29 x i8] c"[DEBUG] Sending message: %s\0A\00"
@str = [22 x i8] c"[ERROR] Write failed.\00"
@str.3 = [29 x i8] c"[DEBUG] Awaiting response...\00"
define i8* @return_service_requested(i32 %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add nsw i64 %7, 1
%9 = tail call i32 @write(i32 %0, i8* %1, i64 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %16
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
%15 = tail call i8* @read_some(i32 %0)
br label %16
16: ; preds = %13, %11
%17 = phi i8* [ %15, %13 ], [ null, %11 ]
ret i8* %17
}