#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 mls_conf {
  int dummy;
};

/* Variables and functions */
int UCHAR_MAX;
int mls_conf_set(struct mls_conf *, char *, char *);
int /*<<< orphan*/ mls_conf_store(struct mls_conf *);
int /*<<< orphan*/ mls_type_data_bytearray_to_str(char *, unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int mls_type_data_put_bytearray(struct mls_conf *storage, unsigned char epc,
                                unsigned char *inb, int size) {
  int ret = 0;
  char key[2 + 1];
  char val[UCHAR_MAX * 2 + 1];
  sprintf(key, "%02X", epc);
  mls_type_data_bytearray_to_str(val, inb, size);
  ret = mls_conf_set(storage, key, val);
  if (ret != 0) {
    goto out;
  }
  mls_conf_store(storage);
out:
  return ret;
}


x86 assembly (clang, -O0):
<mls_type_data_put_bytearray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x23(%rbp),%rdi
lea    0xe63(%rip),%rsi
movzbl -0x9(%rbp),%edx
call   1050 <sprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <mls_type_data_bytearray_to_str@plt>
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rdi
lea    -0x23(%rbp),%rsi
call   1040 <mls_conf_set@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11d9 <mls_type_data_put_bytearray+0x99>
jmp    11e2 <mls_type_data_put_bytearray+0xa2>
mov    -0x8(%rbp),%rdi
call   1030 <mls_conf_store@plt>
mov    -0x20(%rbp),%eax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mls_type_data_put_bytearray>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %esi,%edx
mov    %rdi,%r14
mov    %rsp,-0x38(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe7a(%rip),%rsi
lea    -0x2b(%rbp),%r13
mov    %r13,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1060 <mls_type_data_bytearray_to_str@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <mls_conf_set@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11bc <mls_type_data_put_bytearray+0x7c>
mov    %r14,%rdi
call   1030 <mls_conf_store@plt>
mov    -0x38(%rbp),%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mls_conf = type { i32 }
@UCHAR_MAX = global i32 0
@.str = [5 x i8] c"%02X\00"
define i32 @mls_type_data_put_bytearray(%struct.mls_conf* %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca %struct.mls_conf*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x i8]
%11 = alloca i8*
%12 = alloca i64
store %struct.mls_conf* %0, %struct.mls_conf** %5
store i8 %1, i8* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
%13 = load i32, i32* @UCHAR_MAX
%14 = mul nsw i32 %13, 2
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%20 = load i8, i8* %6
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %20)
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @mls_type_data_bytearray_to_str(i8* %18, i8* %22, i32 %23)
%25 = load %struct.mls_conf*, %struct.mls_conf** %5
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%27 = call i32 @mls_conf_set(%struct.mls_conf* %25, i8* %26, i8* %18)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %4
br label %34
31: ; preds = %4
%32 = load %struct.mls_conf*, %struct.mls_conf** %5
%33 = call i32 @mls_conf_store(%struct.mls_conf* %32)
br label %34
34: ; preds = %31, %30
%35 = load i32, i32* %9
%36 = load i8*, i8** %11
ret i32 %35
}

LLVM IR (-O2):
%struct.mls_conf = type { i32 }
@UCHAR_MAX = global i32 0
@.str = [5 x i8] c"%02X\00"
define i32 @mls_type_data_put_bytearray(%struct.mls_conf* %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @UCHAR_MAX
%8 = shl nsw i32 %7, 1
%9 = or i32 %8, 1
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %1)
%14 = call i32 @mls_type_data_bytearray_to_str(i8* %12, i8* %2, i32 %3)
%15 = call i32 @mls_conf_set(%struct.mls_conf* %0, i8* %6, i8* %12)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @mls_conf_store(%struct.mls_conf* %0)
br label %19
19: ; preds = %4, %17
ret i32 %15
}