#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*/ netd_sendmsg(int, char *, int);
int /*<<< orphan*/ printf(char *, int, int, char *);
int handlemsg_worker(int from, char *msg, int len, void **input) {
  int *in = (int *)input;
  if (from != in[0]) {
    printf("Got unexpected message from %d:%d: %s\n", from, len, msg);
  } else {
    netd_sendmsg(in[1], msg, len);
  }
  if (msg[0] == '\1')
    return -2000;
  return 0;
}


x86 assembly (clang, -O0):
<handlemsg_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
je     1168 <handlemsg_worker+0x48>
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    117b <handlemsg_worker+0x5b>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <netd_sendmsg@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1,%eax
jne    1197 <handlemsg_worker+0x77>
movl   $0xfffff830,-0x4(%rbp)
jmp    119e <handlemsg_worker+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handlemsg_worker>:
push   %rbx
mov    %rsi,%rbx
cmp    %edi,(%rcx)
jne    1135 <handlemsg_worker+0x15>
mov    0x4(%rcx),%edi
mov    %rbx,%rsi
call   1040 <netd_sendmsg@plt>
jmp    1146 <handlemsg_worker+0x26>
mov    %edi,%esi
lea    0xec2(%rip),%rdi
mov    %rbx,%rcx
call   1030 <printf@plt>
xor    %ecx,%ecx
cmpb   $0x1,(%rbx)
mov    $0xfffff830,%eax
cmovne %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Got unexpected message from %d:%d: %s\0A\00"
define i32 @handlemsg_worker(i32 %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%11 = load i8**, i8*** %9
%12 = bitcast i8** %11 to i32*
store i32* %12, i32** %10
%13 = load i32, i32* %6
%14 = load i32*, i32** %10
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = icmp ne i32 %13, %16
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = load i8*, i8** %7
%22 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i8* %21)
br label %30
23: ; preds = %4
%24 = load i32*, i32** %10
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i32 @netd_sendmsg(i32 %26, i8* %27, i32 %28)
br label %30
30: ; preds = %23, %18
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 -2000, i32* %5
br label %38
37: ; preds = %30
store i32 0, i32* %5
br label %38
38: ; preds = %37, %36
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [39 x i8] c"Got unexpected message from %d:%d: %s\0A\00"
define i32 @handlemsg_worker(i32 %0, i8* %1, i32 %2, i8** nocapture %3) {
%5 = bitcast i8** %3 to i32*
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, %0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2, i8* %1)
br label %14
10: ; preds = %4
%11 = getelementptr inbounds i32, i32* %5, i64 1
%12 = load i32, i32* %11
%13 = tail call i32 @netd_sendmsg(i32 %12, i8* %1, i32 %2)
br label %14
14: ; preds = %10, %8
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 1
%17 = select i1 %16, i32 -2000, i32 0
ret i32 %17
}