#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 int /*<<< orphan*/ uint8_t;
typedef int uint64_t;
struct message {
  int dummy;
};

/* Variables and functions */
scalar_t__ memcmp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, int);
int msg_get_count(struct message *);
int /*<<< orphan*/ msg_get_elem(struct message *, int, int /*<<< orphan*/ **,
                                int *);
char *tr_malloc(int);
char *read_node(struct message *msg) {
  uint64_t count = msg_get_count(msg);
  if (count != 2)
    return NULL;
  uint8_t *data;
  uint64_t size;
  msg_get_elem(msg, 0, &data, &size);
  if (size != 4 || memcmp(data, "node", 4) != 0)
    return NULL;
  msg_get_elem(msg, 1, &data, &size);
  char *node = tr_malloc(size + 1);
  memcpy(node, data, size);
  node[size] = '\0';
  return node;
}


x86 assembly (clang, -O0):
<read_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <msg_get_count@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
je     117f <read_node+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1211 <read_node+0xc1>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1030 <msg_get_elem@plt>
cmpl   $0x4,-0x24(%rbp)
jne    11bb <read_node+0x6b>
mov    -0x20(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11c8 <read_node+0x78>
movq   $0x0,-0x8(%rbp)
jmp    1211 <read_node+0xc1>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1030 <msg_get_elem@plt>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1070 <tr_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_node>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1060 <msg_get_count@plt>
xor    %r14d,%r14d
cmp    $0x2,%eax
jne    11e3 <read_node+0x93>
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <msg_get_elem@plt>
cmpl   $0x4,0xc(%rsp)
jne    11e3 <read_node+0x93>
mov    0x10(%rsp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11a2 <read_node+0x52>
xor    %r14d,%r14d
jmp    11e3 <read_node+0x93>
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <msg_get_elem@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
call   1070 <tr_malloc@plt>
mov    %rax,%r14
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %rax,%rdi
call   1050 <memcpy@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.message = type { i32 }
@.str = [5 x i8] c"node\00"
define i8* @read_node(%struct.message* %0) {
%2 = alloca i8*
%3 = alloca %struct.message*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store %struct.message* %0, %struct.message** %3
%8 = load %struct.message*, %struct.message** %3
%9 = call i32 @msg_get_count(%struct.message* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* null, i8** %2
br label %38
13: ; preds = %1
%14 = load %struct.message*, %struct.message** %3
%15 = call i32 @msg_get_elem(%struct.message* %14, i32 0, i32** %5, i32* %6)
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 4
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32*, i32** %5
%20 = call i64 @memcmp(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18, %13
store i8* null, i8** %2
br label %38
23: ; preds = %18
%24 = load %struct.message*, %struct.message** %3
%25 = call i32 @msg_get_elem(%struct.message* %24, i32 1, i32** %5, i32* %6)
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = call i8* @tr_malloc(i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = load i32*, i32** %5
%31 = load i32, i32* %6
%32 = call i32 @memcpy(i8* %29, i32* %30, i32 %31)
%33 = load i8*, i8** %7
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %7
store i8* %37, i8** %2
br label %38
38: ; preds = %23, %22, %12
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
%struct.message = type { i32 }
@.str = [5 x i8] c"node\00"
define i8* @read_node(%struct.message* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = tail call i32 @msg_get_count(%struct.message* %0)
%5 = icmp eq i32 %4, 2
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = bitcast i32** %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = call i32 @msg_get_elem(%struct.message* %0, i32 0, i32** %2, i32* %3)
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %27
12: ; preds = %6
%13 = load i32*, i32** %2
%14 = call i64 @memcmp(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = call i32 @msg_get_elem(%struct.message* %0, i32 1, i32** %2, i32* %3)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = call i8* @tr_malloc(i32 %19)
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = call i32 @memcpy(i8* %20, i32* %21, i32 %22)
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %20, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %6, %12, %16
%28 = phi i8* [ %20, %16 ], [ null, %12 ], [ null, %6 ]
br label %29
29: ; preds = %1, %27
%30 = phi i8* [ %28, %27 ], [ null, %1 ]
ret i8* %30
}