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

/* Variables and functions */
scalar_t__ ECANCELED;
int /*<<< orphan*/ assert(int);
int dill_chsend(int, int *, int, 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();
scalar_t__ errno;
int snprintf(char *, int, char *, char *);
__attribute__((no)) void dialogue(int s, int ch) {
  int op = 1;
  int rc = dill_chsend(ch, &op, sizeof(op), -1);
  assert(rc == 0);
  int64_t deadline = dill_now() + 60000;
  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:
  op = errno == 0 ? 2 : 3;
  rc = dill_chsend(ch, &op, sizeof(op), -1);
  assert(rc == 0 || errno == ECANCELED);
  rc = dill_hclose(s);
  assert(rc == 0);
}


x86 assembly (clang, -O0):
<dialogue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chsend@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1090 <dill_now@plt>
add    $0xea60,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rcx
lea    0xe2f(%rip),%rsi
mov    $0x11,%edx
call   1030 <dill_msend@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ed <dialogue+0x7d>
jmp    127d <dialogue+0x10d>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x100,%edx
call   1080 <dill_mrecv@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jae    121f <dialogue+0xaf>
jmp    127d <dialogue+0x10d>
mov    -0x128(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x230(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x100,%esi
lea    0xdca(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <dill_msend@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1278 <dialogue+0x108>
jmp    127d <dialogue+0x10d>
jmp    127d <dialogue+0x10d>
mov    0x2d54(%rip),%rax
mov    (%rax),%rdx
mov    $0x3,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chsend@plt>
mov    %eax,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x231(%rbp)
je     12e3 <dialogue+0x173>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x231(%rbp)
mov    -0x231(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x4(%rbp),%edi
call   1060 <dill_hclose@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dialogue>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chsend@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1090 <dill_now@plt>
mov    %rax,%rbp
add    $0xea60,%rbp
lea    0xe38(%rip),%rsi
mov    %ebx,%edi
mov    $0x11,%edx
mov    %rbp,%rcx
call   1030 <dill_msend@plt>
test   %eax,%eax
jne    1225 <dialogue+0xb5>
lea    0x10(%rsp),%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x100,%edx
mov    %rbp,%rcx
call   1080 <dill_mrecv@plt>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe14(%rip),%rdx
lea    0x110(%rsp),%r12
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r15,%rcx
call   1050 <snprintf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbp,%rcx
call   1030 <dill_msend@plt>
mov    0x2dac(%rip),%rbp
cmpq   $0x1,0x0(%rbp)
mov    $0x3,%eax
sbb    $0x0,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
call   1040 <dill_chsend@plt>
test   %eax,%eax
sete   %al
mov    0x0(%rbp),%rcx
mov    0x2d84(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1070 <assert@plt>
mov    %ebx,%edi
call   1060 <dill_hclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
add    $0x210,%rsp
pop    %rbx
pop    %r12
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"
@errno = global i64 0
@ECANCELED = global i64 0
define void @dialogue(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca [256 x i8]
%9 = alloca i64
%10 = alloca [256 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %5
%11 = load i32, i32* %4
%12 = call i32 @dill_chsend(i32 %11, i32* %5, i32 4, i32 -1)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i64 (...) @dill_now()
%18 = add nsw i64 %17, 60000
store i64 %18, i64* %7
%19 = load i32, i32* %3
%20 = load i64, i64* %7
%21 = call i32 @dill_msend(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 17, i64 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
br label %48
25: ; preds = %2
%26 = load i32, i32* %3
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i64, i64* %7
%29 = call i64 @dill_mrecv(i32 %26, i8* %27, i32 256, i64 %28)
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = icmp ult i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
br label %48
33: ; preds = %25
%34 = load i64, i64* %9
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%38 = call i32 @snprintf(i8* %36, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %37)
store i32 %38, i32* %6
%39 = load i32, i32* %3
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%41 = load i32, i32* %6
%42 = load i64, i64* %7
%43 = call i32 @dill_msend(i32 %39, i8* %40, i32 %41, i64 %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %33
br label %48
47: ; preds = %33
br label %48
48: ; preds = %47, %46, %32, %24
%49 = load i64, i64* @errno
%50 = icmp eq i64 %49, 0
%51 = zext i1 %50 to i64
%52 = select i1 %50, i32 2, i32 3
store i32 %52, i32* %5
%53 = load i32, i32* %4
%54 = call i32 @dill_chsend(i32 %53, i32* %5, i32 4, i32 -1)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp eq i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %48
%58 = load i64, i64* @errno
%59 = load i64, i64* @ECANCELED
%60 = icmp eq i64 %58, %59
br label %61
61: ; preds = %57, %48
%62 = phi i1 [ true, %48 ], [ %60, %57 ]
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i32, i32* %3
%66 = call i32 @dill_hclose(i32 %65)
store i32 %66, i32* %6
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 0
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
ret void
}

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