#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 /*<<< orphan*/ va_list;

/* Variables and functions */
int /*<<< orphan*/ LOG_EMERG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ RTLD_NOW;
int /*<<< orphan*/ dlclose(void *);
void *dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
scalar_t__ posix_memalign(void **, int, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ vsyslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void validCode(va_list valist_arg1, va_list valist_arg2) {
  void *ptr;
  if (posix_memalign(&ptr, sizeof(void *), sizeof(void *)) == 0)
    free(ptr);
  syslog(LOG_ERR, "err %u", 0U);
  syslog(LOG_WARNING, "warn %d %d", 5, 1);
  vsyslog(LOG_EMERG, "emerg %d", valist_arg1);
  vsyslog(LOG_INFO, "test %s %d %p", valist_arg2);
  void *handle = dlopen("/lib.so", RTLD_NOW);
  if (handle) {
    dlclose(handle);
  }
}


x86 assembly (clang, -O0):
<validCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x8,%edx
mov    %edx,%esi
call   1070 <posix_memalign@plt>
cmp    $0x0,%rax
jne    1191 <validCode+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <syslog@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x5,%edx
mov    $0x1,%ecx
mov    $0x0,%al
call   1050 <syslog@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe34(%rip),%rsi
call   1060 <vsyslog@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe25(%rip),%rsi
call   1060 <vsyslog@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1228 <validCode+0xc8>
mov    -0x18(%rbp),%rdi
call   1080 <dlclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validCode>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x8,%edx
call   1070 <posix_memalign@plt>
test   %rax,%rax
jne    1187 <validCode+0x27>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x5,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
mov    %ebp,%edx
call   1060 <vsyslog@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    %ebx,%edx
call   1060 <vsyslog@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xe2a(%rip),%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1211 <validCode+0xb1>
mov    %rax,%rdi
call   1080 <dlclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [7 x i8] c"err %u\00"
@LOG_WARNING = global i32 0
@.str.1 = [11 x i8] c"warn %d %d\00"
@LOG_EMERG = global i32 0
@.str.2 = [9 x i8] c"emerg %d\00"
@LOG_INFO = global i32 0
@.str.3 = [14 x i8] c"test %s %d %p\00"
@.str.4 = [8 x i8] c"/lib.so\00"
@RTLD_NOW = global i32 0
define void @validCode(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i64 @posix_memalign(i8** %5, i32 8, i32 8)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i32 @free(i8* %10)
br label %12
12: ; preds = %9, %2
%13 = load i32, i32* @LOG_ERR
%14 = call i32 (i32, i8*, i32, ...) @syslog(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%15 = load i32, i32* @LOG_WARNING
%16 = call i32 (i32, i8*, i32, ...) @syslog(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 1)
%17 = load i32, i32* @LOG_EMERG
%18 = load i32, i32* %3
%19 = call i32 @vsyslog(i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @LOG_INFO
%21 = load i32, i32* %4
%22 = call i32 @vsyslog(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @RTLD_NOW
%24 = call i8* @dlopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %12
%28 = load i8*, i8** %6
%29 = call i32 @dlclose(i8* %28)
br label %30
30: ; preds = %27, %12
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [7 x i8] c"err %u\00"
@LOG_WARNING = global i32 0
@.str.1 = [11 x i8] c"warn %d %d\00"
@LOG_EMERG = global i32 0
@.str.2 = [9 x i8] c"emerg %d\00"
@LOG_INFO = global i32 0
@.str.3 = [14 x i8] c"test %s %d %p\00"
@.str.4 = [8 x i8] c"/lib.so\00"
@RTLD_NOW = global i32 0
define void @validCode(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @posix_memalign(i8** %3, i32 8, i32 8)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 @free(i8* %8)
br label %10
10: ; preds = %7, %2
%11 = load i32, i32* @LOG_ERR
%12 = call i32 (i32, i8*, i32, ...) @syslog(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%13 = load i32, i32* @LOG_WARNING
%14 = call i32 (i32, i8*, i32, ...) @syslog(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 1)
%15 = load i32, i32* @LOG_EMERG
%16 = call i32 @vsyslog(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%17 = load i32, i32* @LOG_INFO
%18 = call i32 @vsyslog(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%19 = load i32, i32* @RTLD_NOW
%20 = call i8* @dlopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %10
%23 = call i32 @dlclose(i8* %20)
br label %24
24: ; preds = %22, %10
ret void
}