#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 blob_buf {
  int dummy;
};
struct blob_attr {
  int dummy;
};

/* Variables and functions */
struct blob_attr *blobmsg_new(struct blob_buf *, int, char const *, int,
                              void **);
int /*<<< orphan*/ memcpy(void *, void const *, int);
int blobmsg_add_field(struct blob_buf *buf, int type, const char *name,
                      const void *data, int len) {
  struct blob_attr *attr;
  void *data_dest;
  attr = blobmsg_new(buf, type, name, len, &data_dest);
  if (!attr)
    return -1;
  if (len > 0)
    memcpy(data_dest, data, len);
  return 0;
}


x86 assembly (clang, -O0):
<blobmsg_add_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    -0x40(%rbp),%r8
call   1030 <blobmsg_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    116d <blobmsg_add_field+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <blobmsg_add_field+0x6e>
cmpl   $0x0,-0x2c(%rbp)
jle    1187 <blobmsg_add_field+0x67>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blobmsg_add_field>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
lea    0x8(%rsp),%r8
mov    %ebx,%ecx
call   1030 <blobmsg_new@plt>
test   %rax,%rax
je     1156 <blobmsg_add_field+0x36>
xor    %ebp,%ebp
test   %ebx,%ebx
jle    115b <blobmsg_add_field+0x3b>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
jmp    115b <blobmsg_add_field+0x3b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.blob_buf = type { i32 }
%struct.blob_attr = type { i32 }
define i32 @blobmsg_add_field(%struct.blob_buf* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = call %struct.blob_attr* @blobmsg_new(%struct.blob_buf* %0, i32 %1, i8* %2, i32 %4, i8** %6)
%9 = icmp eq %struct.blob_attr* %8, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = load i8*, i8** %6
%14 = call i32 @memcpy(i8* %13, i8* %3, i32 %4)
br label %15
15: ; preds = %10, %12, %5
%16 = phi i32 [ -1, %5 ], [ 0, %12 ], [ 0, %10 ]
ret i32 %16
}