#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*/ printf(char *, ...);
int handlemsg_master(int from, char *msg, int len, void **result) {
  int ret = 0;
  if (len > 0) {
    if (msg[0] == '\1') {
      printf("Successful termination.");
      ret = -2000;
    } else {
      printf("Got message from %d:%d: %s\n", from, len, msg);
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<handlemsg_master>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    117e <handlemsg_master+0x6e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1,%eax
jne    1161 <handlemsg_master+0x51>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffff830,-0x24(%rbp)
jmp    1179 <handlemsg_master+0x69>
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117e <handlemsg_master+0x6e>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handlemsg_master>:
push   %rbx
test   %edx,%edx
jle    1132 <handlemsg_master+0x22>
mov    %rsi,%rcx
cmpb   $0x1,(%rsi)
jne    1136 <handlemsg_master+0x26>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xfffff830,%ebx
jmp    1148 <handlemsg_master+0x38>
xor    %ebx,%ebx
jmp    1148 <handlemsg_master+0x38>
mov    %edi,%esi
lea    0xed9(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"Successful termination.\00"
@.str.1 = [28 x i8] c"Got message from %d:%d: %s\0A\00"
define i32 @handlemsg_master(i32 %0, i8* %1, i32 %2, i8** nocapture readnone %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %13
6: ; preds = %4
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %2, i8* %1)
br label %13
13: ; preds = %9, %11, %4
%14 = phi i32 [ -2000, %9 ], [ 0, %11 ], [ 0, %4 ]
ret i32 %14
}