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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int dill_hclose(int);
size_t dill_mrecv(int, char *, int, scalar_t__);
int dill_msend(int, char *, int, scalar_t__);
scalar_t__ dill_now();
int snprintf(char *, int, char *, char *);
__attribute__((no)) void dialogue(int s) {
  int64_t deadline = dill_now() + 60000;
  int rc = dill_msend(s, "What's your name?", 17, deadline);
  if (rc != 0)
    goto cleanup;
  char inbuf[256];
  ssize_t sz = dill_mrecv(s, inbuf, sizeof(inbuf), deadline);
  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, deadline);
  if (rc != 0)
    goto cleanup;
cleanup:
  rc = dill_hclose(s);
  assert(rc == 0);
}


x86 assembly (clang, -O0):
<dialogue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1080 <dill_now@plt>
add    $0xea60,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rcx
lea    0xe73(%rip),%rsi
mov    $0x11,%edx
call   1030 <dill_msend@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a9 <dialogue+0x49>
jmp    1239 <dialogue+0xd9>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x100,%edx
call   1070 <dill_mrecv@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jae    11db <dialogue+0x7b>
jmp    1239 <dialogue+0xd9>
mov    -0x128(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x230(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x100,%esi
lea    0xe0e(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1030 <dill_msend@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1234 <dialogue+0xd4>
jmp    1239 <dialogue+0xd9>
jmp    1239 <dialogue+0xd9>
mov    -0x4(%rbp),%edi
call   1050 <dill_hclose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dialogue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <dill_now@plt>
mov    %rax,%rbx
add    $0xea60,%rbx
lea    0xe79(%rip),%rsi
mov    %ebp,%edi
mov    $0x11,%edx
mov    %rbx,%rcx
call   1030 <dill_msend@plt>
test   %eax,%eax
jne    11e1 <dialogue+0x81>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1070 <dill_mrecv@plt>
movb   $0x0,(%rsp,%rax,1)
lea    0xe58(%rip),%rdx
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1030 <dill_msend@plt>
mov    %ebp,%edi
call   1050 <dill_hclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 i64
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = alloca [256 x i8]
store i32 %0, i32* %2
%8 = call i64 (...) @dill_now()
%9 = add nsw i64 %8, 60000
store i64 %9, i64* %3
%10 = load i32, i32* %2
%11 = load i64, i64* %3
%12 = call i32 @dill_msend(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 17, i64 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
br label %39
16: ; preds = %1
%17 = load i32, i32* %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = load i64, i64* %3
%20 = call i64 @dill_mrecv(i32 %17, i8* %18, i32 256, i64 %19)
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = icmp ult i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
br label %39
24: ; preds = %16
%25 = load i64, i64* %6
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i32 @snprintf(i8* %27, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 %29, i32* %4
%30 = load i32, i32* %2
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %4
%33 = load i64, i64* %3
%34 = call i32 @dill_msend(i32 %30, i8* %31, i32 %32, i64 %33)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %24
br label %39
38: ; preds = %24
br label %39
39: ; preds = %38, %37, %23, %15
%40 = load i32, i32* %2
%41 = call i32 @dill_hclose(i32 %40)
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
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 i64 (...) @dill_now()
%5 = add nsw i64 %4, 60000
%6 = tail call i32 @dill_msend(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 17, i64 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%10 = call i64 @dill_mrecv(i32 %0, i8* %9, i32 256, i64 %5)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 @snprintf(i8* %12, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%14 = call i32 @dill_msend(i32 %0, i8* %12, i32 %13, i64 %5)
br label %15
15: ; preds = %8, %1
%16 = call i32 @dill_hclose(i32 %0)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
ret void
}