#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 */
struct rq_xml_node {
  int dummy;
};

/* Variables and functions */
struct rq_xml_node *rq_xml_node_find(struct rq_xml_node *, char const *);
int rq_xml_node_get_text(struct rq_xml_node *, char *, unsigned int);
unsigned rq_xml_node_find_text(struct rq_xml_node *root_node, const char *xpath,
                               char *buf, unsigned max_buf_len) {
  struct rq_xml_node *node = rq_xml_node_find(root_node, xpath);
  if (node)
    return rq_xml_node_get_text(node, buf, max_buf_len);
  else if (max_buf_len > 0)
    buf[0] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<rq_xml_node_find_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <rq_xml_node_find@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     116b <rq_xml_node_find_text+0x4b>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <rq_xml_node_get_text@plt>
mov    %eax,-0x4(%rbp)
jmp    1188 <rq_xml_node_find_text+0x68>
cmpl   $0x0,-0x24(%rbp)
jbe    117c <rq_xml_node_find_text+0x5c>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1181 <rq_xml_node_find_text+0x61>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_xml_node_find_text>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
call   1040 <rq_xml_node_find@plt>
test   %rax,%rax
je     1145 <rq_xml_node_find_text+0x25>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <rq_xml_node_get_text@plt>
test   %ebp,%ebp
je     114c <rq_xml_node_find_text+0x2c>
movb   $0x0,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rq_xml_node = type { i32 }
define i32 @rq_xml_node_find_text(%struct.rq_xml_node* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.rq_xml_node*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.rq_xml_node*
store %struct.rq_xml_node* %0, %struct.rq_xml_node** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load %struct.rq_xml_node*, %struct.rq_xml_node** %6
%12 = load i8*, i8** %7
%13 = call %struct.rq_xml_node* @rq_xml_node_find(%struct.rq_xml_node* %11, i8* %12)
store %struct.rq_xml_node* %13, %struct.rq_xml_node** %10
%14 = load %struct.rq_xml_node*, %struct.rq_xml_node** %10
%15 = icmp ne %struct.rq_xml_node* %14, null
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load %struct.rq_xml_node*, %struct.rq_xml_node** %10
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = call i32 @rq_xml_node_get_text(%struct.rq_xml_node* %17, i8* %18, i32 %19)
store i32 %20, i32* %5
br label %29
21: ; preds = %4
%22 = load i32, i32* %9
%23 = icmp ugt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27
store i32 0, i32* %5
br label %29
29: ; preds = %28, %16
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
%struct.rq_xml_node = type { i32 }
define i32 @rq_xml_node_find_text(%struct.rq_xml_node* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call %struct.rq_xml_node* @rq_xml_node_find(%struct.rq_xml_node* %0, i8* %1)
%6 = icmp eq %struct.rq_xml_node* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @rq_xml_node_get_text(%struct.rq_xml_node* %5, i8* %2, i32 %3)
br label %12
9: ; preds = %4
%10 = icmp eq i32 %3, 0
br i1 %10, label %12, label %11
11: ; preds = %9
store i8 0, i8* %2
br label %12
12: ; preds = %11, %9, %7
%13 = phi i32 [ %8, %7 ], [ 0, %9 ], [ 0, %11 ]
ret i32 %13
}