#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 size_t ssize_t;
typedef int /*<<< orphan*/ outbuf;
typedef int /*<<< orphan*/ inbuf;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int dill_hclose(int);
size_t dill_mrecv(int, char *, int, int);
int dill_msend(int, char *, int, int);
int snprintf(char *, int, char *, char *);
__attribute__((no)) void dialogue(int s) {
  int rc = dill_msend(s, "What's your name?", 17, -1);
  if (rc != 0)
    goto cleanup;
  char inbuf[256];
  ssize_t sz = dill_mrecv(s, inbuf, sizeof(inbuf), -1);
  if (sz < 0)
    goto cleanup;
  inbuf[sz] = 0;
  char outbuf[256];
  rc = snprintf(outbuf, sizeof(outbuf), "Hello, %s!", inbuf);
  rc = dill_msend(s, outbuf, rc, -1);
  if (rc != 0)
    goto cleanup;
cleanup:
  rc = dill_hclose(s);
  assert(rc == 0);
}


x86 assembly (clang, -O0):
<dialogue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe98(%rip),%rsi
mov    $0x11,%edx
mov    $0xffffffff,%ecx
call   1030 <dill_msend@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1189 <dialogue+0x39>
jmp    121b <dialogue+0xcb>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
mov    $0xffffffff,%ecx
call   1070 <dill_mrecv@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jae    11bc <dialogue+0x6c>
jmp    121b <dialogue+0xcb>
mov    -0x118(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rcx
mov    $0x100,%esi
lea    0xe2d(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0xffffffff,%ecx
call   1030 <dill_msend@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1216 <dialogue+0xc6>
jmp    121b <dialogue+0xcb>
jmp    121b <dialogue+0xcb>
mov    -0x4(%rbp),%edi
call   1050 <dill_hclose@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dialogue>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %edi,%ebx
lea    0xe9b(%rip),%rsi
mov    $0x11,%edx
mov    $0xffffffff,%ecx
call   1030 <dill_msend@plt>
test   %eax,%eax
jne    11c3 <dialogue+0x73>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
mov    $0xffffffff,%ecx
call   1070 <dill_mrecv@plt>
movb   $0x0,(%rsp,%rax,1)
lea    0xe78(%rip),%rdx
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
mov    $0xffffffff,%ecx
call   1030 <dill_msend@plt>
mov    %ebx,%edi
call   1050 <dill_hclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"What's your name?\00"
@.str.1 = [11 x i8] c"Hello, %s!\00"
define void @dialogue(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i64
%6 = alloca [256 x i8]
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @dill_msend(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 17, i32 -1)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
br label %33
12: ; preds = %1
%13 = load i32, i32* %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i64 @dill_mrecv(i32 %13, i8* %14, i32 256, i32 -1)
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = icmp ult i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %33
19: ; preds = %12
%20 = load i64, i64* %5
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 @snprintf(i8* %22, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 %24, i32* %3
%25 = load i32, i32* %2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %3
%28 = call i32 @dill_msend(i32 %25, i8* %26, i32 %27, i32 -1)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %19
br label %33
32: ; preds = %19
br label %33
33: ; preds = %32, %31, %18, %11
%34 = load i32, i32* %2
%35 = call i32 @dill_hclose(i32 %34)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"What's your name?\00"
@.str.1 = [11 x i8] c"Hello, %s!\00"
define void @dialogue(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = tail call i32 @dill_msend(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 17, i32 -1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = call i64 @dill_mrecv(i32 %0, i8* %7, i32 256, i32 -1)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%12 = call i32 @dill_msend(i32 %0, i8* %10, i32 %11, i32 -1)
br label %13
13: ; preds = %6, %1
%14 = call i32 @dill_hclose(i32 %0)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
ret void
}