#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 char uint8_t;
typedef int /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ memcpy(char *, void const *, int const);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *,
                          int /*<<< orphan*/ const, char *);
void dhcpv6_log_status_code(const uint16_t code, const char *scope,
                            const void *status_msg, const int len) {
  uint8_t buf[len + 3];
  memset(buf, 0, sizeof(buf));
  if (len) {
    buf[0] = '(';
    memcpy(&buf[1], status_msg, len);
    buf[len + 1] = ')';
  }
  syslog(LOG_WARNING, "Server returned %s status %i %s", scope, code, buf);
}


x86 assembly (clang, -O0):
<dhcpv6_log_status_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11aa <dhcpv6_log_status_code+0x7a>
mov    -0x38(%rbp),%rdi
movb   $0x28,(%rdi)
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x29,(%rax,%rcx,1)
mov    -0x38(%rbp),%r8
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe3b(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhcpv6_log_status_code>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x3(%r12),%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
test   %r12d,%r12d
je     1189 <dhcpv6_log_status_code+0x59>
movb   $0x28,(%rbx)
lea    0x1(%rbx),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %r12d,%rax
movb   $0x29,0x1(%rax,%rbx,1)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %rbx,%r8
call   1050 <syslog@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_WARNING = global i32 0
@.str = [32 x i8] c"Server returned %s status %i %s\00"
define void @dhcpv6_log_status_code(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = add nsw i32 %11, 3
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = trunc i64 %13 to i32
%17 = call i32 @memset(i8* %15, i32 0, i32 %16)
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %4
%21 = getelementptr inbounds i8, i8* %15, i64 0
store i8 40, i8* %21
%22 = getelementptr inbounds i8, i8* %15, i64 1
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %15, i64 %28
store i8 41, i8* %29
br label %30
30: ; preds = %20, %4
%31 = load i32, i32* @LOG_WARNING
%32 = load i8*, i8** %6
%33 = load i32, i32* %5
%34 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33, i8* %15)
%35 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@LOG_WARNING = global i32 0
@.str = [32 x i8] c"Server returned %s status %i %s\00"
define void @dhcpv6_log_status_code(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = add nsw i32 %3, 3
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @memset(i8* %7, i32 0, i32 %5)
%9 = icmp eq i32 %3, 0
br i1 %9, label %16, label %10
10: ; preds = %4
store i8 40, i8* %7
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = call i32 @memcpy(i8* %11, i8* %2, i32 %3)
%13 = add nsw i32 %3, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 41, i8* %15
br label %16
16: ; preds = %10, %4
%17 = load i32, i32* @LOG_WARNING
%18 = call i32 @syslog(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %0, i8* %7)
ret void
}