#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *libewf_header_value_string_alloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *libewf_header_values_set_value(char *header_value, char *value) {
  uint32_t string_size;
  if (header_value != NULL) {
    free(header_value);
  }
  string_size = strlen(value);
  if (string_size <= 0) {
    return (NULL);
  }
  header_value = libewf_header_value_string_alloc(string_size + 1);
  memcpy((char *)header_value, (char *)value, string_size);
  header_value[string_size] = '\0';
  return (header_value);
}


x86 assembly (clang, -O0):
<libewf_header_values_set_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1164 <libewf_header_values_set_value+0x24>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1187 <libewf_header_values_set_value+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11ba <libewf_header_values_set_value+0x7a>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libewf_header_values_set_value>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1152 <libewf_header_values_set_value+0x12>
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1181 <libewf_header_values_set_value+0x41>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1050 <libewf_header_value_string_alloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
jmp    1184 <libewf_header_values_set_value+0x44>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @libewf_header_values_set_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @free(i8* %10)
br label %12
12: ; preds = %9, %2
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i8* null, i8** %3
br label %31
18: ; preds = %12
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = call i8* @libewf_header_value_string_alloc(i32 %20)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %31
31: ; preds = %18, %17
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @libewf_header_values_set_value(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @free(i8* %0)
br label %6
6: ; preds = %4, %2
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp slt i32 %7, 1
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = add nuw nsw i32 %7, 1
%11 = tail call i8* @libewf_header_value_string_alloc(i32 %10)
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i32 %7)
%13 = zext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %6, %9
%16 = phi i8* [ %11, %9 ], [ null, %6 ]
ret i8* %16
}