#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_AUTH;
int /*<<< orphan*/ LOG_PID;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *strdup(char const *);
int strlen(char *);
int /*<<< orphan*/ vsyslog(int, char *, int /*<<< orphan*/);
void _log_syslog(int level, const char *format, va_list ap) {
  int i;
  char *fmt;
  fmt = strdup(format);
  openlog("pam_pcsc", LOG_PID, LOG_AUTH);
  for (i = 0; i < strlen(fmt) - 1; ++i)
    if (fmt[i] == '\n')
      fmt[i] = ';';
  vsyslog(level, fmt, ap);
  closelog();
  free(fmt);
}


x86 assembly (clang, -O0):
<_log_syslog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
lea    0xe68(%rip),%rdi
call   1070 <openlog@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f7 <_log_syslog+0x97>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11e4 <_log_syslog+0x84>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x3b,(%rax,%rcx,1)
jmp    11e9 <_log_syslog+0x89>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <_log_syslog+0x44>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <vsyslog@plt>
mov    $0x0,%al
call   1040 <closelog@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_log_syslog>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%r15d
mov    %rsi,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    0xe6f(%rip),%rdi
call   1070 <openlog@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11d2 <_log_syslog+0x72>
xor    %ebp,%ebp
jmp    11c6 <_log_syslog+0x66>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jge    11d2 <_log_syslog+0x72>
cmpb   $0xa,(%rbx,%rbp,1)
jne    11b0 <_log_syslog+0x50>
movb   $0x3b,(%rbx,%rbp,1)
jmp    11b0 <_log_syslog+0x50>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <vsyslog@plt>
xor    %eax,%eax
call   1040 <closelog@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"pam_pcsc\00"
@LOG_PID = global i32 0
@LOG_AUTH = global i32 0
define void @_log_syslog(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %8
%11 = load i32, i32* @LOG_PID
%12 = load i32, i32* @LOG_AUTH
%13 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
store i32 0, i32* %7
br label %14
14: ; preds = %34, %3
%15 = load i32, i32* %7
%16 = load i8*, i8** %8
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %15, %18
br i1 %19, label %20, label %37
20: ; preds = %14
%21 = load i8*, i8** %8
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8*, i8** %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 59, i8* %32
br label %33
33: ; preds = %28, %20
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %14
37: ; preds = %14
%38 = load i32, i32* %4
%39 = load i8*, i8** %8
%40 = load i32, i32* %6
%41 = call i32 @vsyslog(i32 %38, i8* %39, i32 %40)
%42 = call i32 (...) @closelog()
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"pam_pcsc\00"
@LOG_PID = global i32 0
@LOG_AUTH = global i32 0
define void @_log_syslog(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strdup(i8* %1)
%5 = load i32, i32* @LOG_PID
%6 = load i32, i32* @LOG_AUTH
%7 = tail call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 @strlen(i8* %4)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %3, %16
%11 = phi i64 [ %17, %16 ], [ 0, %3 ]
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %10
store i8 59, i8* %12
br label %16
16: ; preds = %10, %15
%17 = add nuw nsw i64 %11, 1
%18 = tail call i32 @strlen(i8* %4)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %17, %20
br i1 %21, label %10, label %22
22: ; preds = %16, %3
%23 = tail call i32 @vsyslog(i32 %0, i8* %4, i32 %2)
%24 = tail call i32 (...) @closelog()
%25 = tail call i32 @free(i8* %4)
ret void
}