#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ printf(char *);
size_t strlen(char *);
int setErrorMsg(char *Errormsg, char *datagram) {
  char *tmp;
  if (Errormsg == NULL) {
    printf("Error msg is not set ! \n");
    exit(EXIT_FAILURE);
  }
  tmp = datagram;
  tmp += 4;
  memcpy(tmp, Errormsg, strlen(Errormsg));
  tmp[strlen(Errormsg)] = 0;
  return 1;
}


x86 assembly (clang, -O0):
<setErrorMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1175 <setErrorMsg+0x35>
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setErrorMsg>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1180 <setErrorMsg+0x40>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rsi),%r15
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,0x4(%r14,%rax,1)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Error msg is not set ! \0A\00"
@EXIT_FAILURE = global i32 0
define i32 @setErrorMsg(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i8*, i8** %4
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 4
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
%20 = call i32 @memcpy(i8* %16, i8* %17, i64 %19)
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = call i64 @strlen(i8* %22)
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
ret i32 1
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [24 x i8] c"Error msg is not set ! \00"
define i32 @setErrorMsg(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %1, i64 4
%10 = tail call i64 @strlen(i8* %0)
%11 = tail call i32 @memcpy(i8* %9, i8* %0, i64 %10)
%12 = tail call i64 @strlen(i8* %0)
%13 = getelementptr inbounds i8, i8* %9, i64 %12
store i8 0, i8* %13
ret i32 1
}