#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*/ snprintf(char *, int, char *, char const *, char const *,
                            ...);
int /*<<< orphan*/ strerror(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void log_error(const char *msg, const char *name, int err, int fd) {
  static char str[1024];
  if (err) {
    snprintf(str, 1024, "falogd: %s%s: %s\n", msg, name ? name : "",
             strerror(err));
  } else {
    snprintf(str, 1024, "falogd: %s%s\n", msg, name ? name : "");
  }
  write(fd, str, strlen(str));
}


x86 assembly (clang, -O0):
<log_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ca <log_error+0x8a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1180 <log_error+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <log_error+0x50>
lea    0xe8a(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <log_error+0x50>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    %eax,%r9d
lea    0x2e9e(%rip),%rdi
mov    $0x400,%esi
lea    0xe42(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    121c <log_error+0xdc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ea <log_error+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11fa <log_error+0xba>
lea    0xe20(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11fa <log_error+0xba>
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0x2e47(%rip),%rdi
mov    $0x400,%esi
lea    0xdfd(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    0x2e27(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%edx
lea    0x2e16(%rip),%rsi
call   1030 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_error>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdi,%rbp
test   %rsi,%rsi
lea    0xebd(%rip),%rbx
cmovne %rsi,%rbx
test   %edx,%edx
je     1188 <log_error+0x48>
mov    %edx,%edi
call   1060 <strerror@plt>
lea    0x2ee6(%rip),%rdi
lea    0xe8f(%rip),%rdx
mov    $0x400,%esi
mov    %rbp,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11a8 <log_error+0x68>
lea    0x2ec1(%rip),%rdi
lea    0xe7c(%rip),%rdx
mov    $0x400,%esi
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x2ea1(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@log_error.str = internal global [1024 x i8] zeroinitializer
@.str = [18 x i8] c"falogd: %s%s: %s\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"falogd: %s%s\0A\00"
define void @log_error(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %4
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i8*, i8** %6
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %15
%19 = phi i8* [ %16, %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %17 ]
%20 = load i32, i32* %7
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %19, i32 %21)
br label %33
23: ; preds = %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i8*, i8** %6
br label %30
29: ; preds = %23
br label %30
30: ; preds = %29, %27
%31 = phi i8* [ %28, %27 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %29 ]
%32 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %31)
br label %33
33: ; preds = %30, %18
%34 = load i32, i32* %8
%35 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0))
%36 = call i32 @write(i32 %34, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 %35)
ret void
}

LLVM IR (-O2):
@log_error.str = internal global [1024 x i8] zeroinitializer
@.str = [18 x i8] c"falogd: %s%s: %s\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"falogd: %s%s\0A\00"
define void @log_error(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
%6 = icmp eq i8* %1, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %1
br i1 %5, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @strerror(i32 %2)
%10 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7, i32 %9)
br label %13
11: ; preds = %4
%12 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %7)
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0))
%15 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @log_error.str, i64 0, i64 0), i32 %14)
ret void
}