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

/* Variables and functions */
unsigned char *mapGetValueByID(struct s_map *, int const);
int /*<<< orphan*/ mapGetValueSize(struct s_map *);
int /*<<< orphan*/ memcpy(unsigned char *, void const *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
void mapSetValueByID(struct s_map *map, const int id, const void *value) {
  unsigned char *tptr = mapGetValueByID(map, id);
  if ((!(id < 0)) && (map != NULL)) {
    if (value == NULL) {
      memset(tptr, 0, mapGetValueSize(map));
    } else {
      memcpy(tptr, value, mapGetValueSize(map));
    }
  }
}


x86 assembly (clang, -O0):
<mapSetValueByID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <mapGetValueByID@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d3 <mapSetValueByID+0x93>
cmpq   $0x0,-0x8(%rbp)
je     11d3 <mapSetValueByID+0x93>
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <mapSetValueByID+0x66>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mapGetValueSize@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11ce <mapSetValueByID+0x8e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mapGetValueSize@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
jmp    11d3 <mapSetValueByID+0x93>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapSetValueByID>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <mapGetValueByID@plt>
test   %rbx,%rbx
je     1184 <mapSetValueByID+0x44>
test   %ebp,%ebp
js     1184 <mapSetValueByID+0x44>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <mapGetValueSize@plt>
mov    %r14,%rdi
test   %r15,%r15
je     118f <mapSetValueByID+0x4f>
mov    %r15,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %esi,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <memset@plt>

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

LLVM IR (-O2):
%struct.s_map = type { i32 }
define void @mapSetValueByID(%struct.s_map* %0, i32 %1, i8* %2) {
%4 = tail call i8* @mapGetValueByID(%struct.s_map* %0, i32 %1)
%5 = icmp sgt i32 %1, -1
%6 = icmp ne %struct.s_map* %0, null
%7 = and i1 %6, %5
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = icmp eq i8* %2, null
%10 = tail call i32 @mapGetValueSize(%struct.s_map* %0)
br i1 %9, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @memset(i8* %4, i32 0, i32 %10)
br label %15
13: ; preds = %8
%14 = tail call i32 @memcpy(i8* %4, i8* %2, i32 %10)
br label %15
15: ; preds = %11, %13, %3
ret void
}