#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 */
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ namebuf;
typedef int /*<<< orphan*/ msgbuf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
char *eslib_proc_getname();
scalar_t__ eslib_string_copy(int /*<<< orphan*/, char *, int,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ eslib_string_sprintf(char *, int, int /*<<< orphan*/ *,
                                        char *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getpid();
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int sendto(int, char *, unsigned int, int /*<<< orphan*/, struct sockaddr *,
           int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
unsigned int strnlen(char *, int);
int logmsg(char *name, char *msg, int lvl) {
  char msgbuf[1024];
  char namebuf[64];
  struct sockaddr_un addr;
  unsigned int msglen;
  int devlog;
  if (name == NULL)
    eslib_string_sprintf(namebuf, sizeof(namebuf), NULL, "%s [%d]",
                         eslib_proc_getname(), getpid());
  else
    eslib_string_sprintf(namebuf, sizeof(namebuf), NULL, "%s [%d]", name,
                         getpid());
  if (msg == NULL)
    msg = namebuf;
  switch (lvl) {
  default:
  case 1:
    eslib_string_sprintf(msgbuf, sizeof(msgbuf), NULL, "%s info: %s", namebuf,
                         msg);
    break;
  case 2:
    eslib_string_sprintf(msgbuf, sizeof(msgbuf), NULL, "%s error: %s", namebuf,
                         msg);
    break;
  case 3:
    eslib_string_sprintf(msgbuf, sizeof(msgbuf), NULL, "%s critical: %s",
                         namebuf, msg);
    break;
  }
  msglen = strnlen(msgbuf, 1024);
  if (msglen >= 1024)
    msglen = 1024 - 1;
  msgbuf[msglen] = '\0';
  fprintf(stderr, msgbuf);
  fprintf(stderr, "\n");
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  if (eslib_string_copy(addr.sun_path, "/dev/log", sizeof(addr.sun_path), NULL))
    return -1;
  devlog = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (devlog == -1) {
    printf("devlog socket error: %s\n", strerror(errno));
    return -1;
  }
  while (1) {
    int r = sendto(devlog, msgbuf, msglen + 1, MSG_DONTWAIT,
                   (struct sockaddr *)&addr, sizeof(addr));
    if (r == -1 && (errno == EINTR || errno == EAGAIN))
      continue;
    else if (r > 0)
      break;
    else {
      printf("devlog sendto: %s\n", strerror(errno));
      close(devlog);
      return -1;
    }
  }
  close(devlog);
  return 0;
}


x86 assembly (clang, -O0):
<logmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122f <logmsg+0x6f>
lea    -0x460(%rbp),%rax
mov    %rax,-0x488(%rbp)
mov    $0x0,%al
call   10b0 <eslib_proc_getname@plt>
mov    %rax,-0x480(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x488(%rbp),%rdi
mov    -0x480(%rbp),%r8
mov    %rax,%r9
mov    $0x40,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xddb(%rip),%rcx
call   1030 <eslib_string_sprintf@plt>
jmp    1275 <logmsg+0xb5>
lea    -0x460(%rbp),%rax
mov    %rax,-0x498(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x490(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x498(%rbp),%rdi
mov    -0x490(%rbp),%r8
mov    %rax,%r9
mov    $0x40,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd90(%rip),%rcx
call   1030 <eslib_string_sprintf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    128b <logmsg+0xcb>
lea    -0x460(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x49c(%rbp)
sub    $0x1,%eax
je     12cf <logmsg+0x10f>
jmp    12a2 <logmsg+0xe2>
mov    -0x49c(%rbp),%eax
sub    $0x2,%eax
je     12fb <logmsg+0x13b>
jmp    12b6 <logmsg+0xf6>
mov    -0x49c(%rbp),%eax
sub    $0x3,%eax
je     1327 <logmsg+0x167>
jmp    12ca <logmsg+0x10a>
jmp    12cf <logmsg+0x10f>
lea    -0x420(%rbp),%rdi
lea    -0x460(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x400,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd17(%rip),%rcx
call   1030 <eslib_string_sprintf@plt>
jmp    134e <logmsg+0x18e>
lea    -0x420(%rbp),%rdi
lea    -0x460(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x400,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xcf7(%rip),%rcx
call   1030 <eslib_string_sprintf@plt>
jmp    134e <logmsg+0x18e>
lea    -0x420(%rbp),%rdi
lea    -0x460(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x400,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xcd8(%rip),%rcx
call   1030 <eslib_string_sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1070 <strnlen@plt>
mov    %eax,-0x46c(%rbp)
cmpl   $0x400,-0x46c(%rbp)
jb     137f <logmsg+0x1bf>
movl   $0x3ff,-0x46c(%rbp)
mov    -0x46c(%rbp),%eax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
call   10a0 <fprintf@plt>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
lea    0xcb2(%rip),%rsi
call   10a0 <fprintf@plt>
lea    -0x468(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x464(%rbp)
mov    -0x468(%rbp),%edi
lea    0xc4b(%rip),%rsi
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10c0 <eslib_string_copy@plt>
cmp    $0x0,%rax
je     140a <logmsg+0x24a>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <logmsg+0x37b>
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
mov    0x2bc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x470(%rbp)
cmpl   $0xffffffff,-0x470(%rbp)
jne    1460 <logmsg+0x2a0>
mov    0x2b8b(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xbeb(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <logmsg+0x37b>
jmp    1465 <logmsg+0x2a5>
mov    -0x470(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x46c(%rbp),%edx
add    $0x1,%edx
mov    0x2b3e(%rip),%rax
mov    (%rax),%ecx
lea    -0x468(%rbp),%r8
mov    $0x8,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x474(%rbp)
cmpl   $0xffffffff,-0x474(%rbp)
jne    14e2 <logmsg+0x322>
mov    0x2b18(%rip),%rax
mov    (%rax),%rax
mov    0x2afe(%rip),%rcx
cmp    (%rcx),%rax
je     14dd <logmsg+0x31d>
mov    0x2afe(%rip),%rax
mov    (%rax),%rax
mov    0x2ad4(%rip),%rcx
cmp    (%rcx),%rax
jne    14e2 <logmsg+0x322>
jmp    1465 <logmsg+0x2a5>
cmpl   $0x0,-0x474(%rbp)
jle    14f4 <logmsg+0x334>
jmp    1529 <logmsg+0x369>
mov    0x2acd(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xb46(%rip),%rdi
call   1050 <printf@plt>
mov    -0x470(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    153b <logmsg+0x37b>
mov    -0x470(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logmsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
test   %rdi,%rdi
je     11e1 <logmsg+0x21>
mov    %rdi,%rbp
jmp    11eb <logmsg+0x2b>
xor    %eax,%eax
call   10b0 <eslib_proc_getname@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe07(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
xor    %edx,%edx
mov    %rbp,%r8
mov    %rax,%r9
call   1030 <eslib_string_sprintf@plt>
test   %rbx,%rbx
lea    0x10(%rsp),%r8
cmove  %r8,%rbx
cmp    $0x2,%r14d
lea    0xded(%rip),%rax
lea    0xdda(%rip),%rdx
cmove  %rax,%rdx
cmp    $0x3,%r14d
lea    0xde4(%rip),%rcx
cmovne %rdx,%rcx
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
xor    %edx,%edx
mov    %rbx,%r9
call   1030 <eslib_string_sprintf@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   1070 <strnlen@plt>
cmp    $0x3ff,%eax
mov    $0x3ff,%ebx
cmovb  %eax,%ebx
movb   $0x0,0x50(%rsp,%rbx,1)
mov    0x2d52(%rip),%rbp
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   10a0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdd1(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2d38(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xd6f(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10c0 <eslib_string_copy@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    13b6 <logmsg+0x1f6>
mov    0x0(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     135b <logmsg+0x19b>
mov    %eax,%ebp
add    $0x1,%ebx
mov    0x2cbf(%rip),%r14
lea    0x50(%rsp),%r15
lea    0x8(%rsp),%r12
mov    0x2ca6(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%ecx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r12,%r8
mov    $0x8,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    137b <logmsg+0x1bb>
mov    0x2c84(%rip),%rax
mov    (%rax),%rdi
cmp    0x0(%r13),%rdi
je     1320 <logmsg+0x160>
mov    0x2c54(%rip),%rax
cmp    (%rax),%rdi
je     1320 <logmsg+0x160>
jmp    1395 <logmsg+0x1d5>
mov    0x2c66(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xcc9(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    13b6 <logmsg+0x1f6>
test   %eax,%eax
jle    138b <logmsg+0x1cb>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %r14d,%r14d
jmp    13b6 <logmsg+0x1f6>
mov    0x2c36(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xcb2(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"%s [%d]\00"
@.str.1 = [12 x i8] c"%s info: %s\00"
@.str.2 = [13 x i8] c"%s error: %s\00"
@.str.3 = [16 x i8] c"%s critical: %s\00"
@stderr = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@AF_UNIX = global i32 0
@.str.5 = [9 x i8] c"/dev/log\00"
@SOCK_DGRAM = global i32 0
@.str.6 = [25 x i8] c"devlog socket error: %s\0A\00"
@errno = global i64 0
@MSG_DONTWAIT = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.7 = [19 x i8] c"devlog sendto: %s\0A\00"
define i32 @logmsg(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [64 x i8]
%10 = alloca %struct.sockaddr_un
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%18 = call i8* (...) @eslib_proc_getname()
%19 = call i8* (...) @getpid()
%20 = call i32 @eslib_string_sprintf(i8* %17, i32 64, i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
br label %26
21: ; preds = %3
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = call i8* (...) @getpid()
%25 = call i32 @eslib_string_sprintf(i8* %22, i32 64, i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24)
br label %26
26: ; preds = %21, %16
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
store i8* %30, i8** %6
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %7
switch i32 %32, label %33 [
i32 1, label %34
i32 2, label %39
i32 3, label %44
]
33: ; preds = %31
br label %34
34: ; preds = %31, %33
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = call i32 @eslib_string_sprintf(i8* %35, i32 1024, i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %37)
br label %49
39: ; preds = %31
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%42 = load i8*, i8** %6
%43 = call i32 @eslib_string_sprintf(i8* %40, i32 1024, i32* null, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %42)
br label %49
44: ; preds = %31
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%47 = load i8*, i8** %6
%48 = call i32 @eslib_string_sprintf(i8* %45, i32 1024, i32* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %44, %39, %34
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = call i32 @strnlen(i8* %50, i32 1024)
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = icmp uge i32 %52, 1024
br i1 %53, label %54, label %55
54: ; preds = %49
store i32 1023, i32* %11
br label %55
55: ; preds = %54, %49
%56 = load i32, i32* %11
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %57
store i8 0, i8* %58
%59 = load i32, i32* @stderr
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%61 = call i32 @fprintf(i32 %59, i8* %60)
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @memset(%struct.sockaddr_un* %10, i32 0, i32 8)
%65 = load i32, i32* @AF_UNIX
%66 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 1
store i32 %65, i32* %66
%67 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i64 @eslib_string_copy(i32 %68, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 4, i32* null)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %55
store i32 -1, i32* %4
br label %115
72: ; preds = %55
%73 = load i32, i32* @AF_UNIX
%74 = load i32, i32* @SOCK_DGRAM
%75 = call i32 @socket(i32 %73, i32 %74, i32 0)
store i32 %75, i32* %12
%76 = load i32, i32* %12
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %72
%79 = load i64, i64* @errno
%80 = call i8* @strerror(i64 %79)
%81 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %80)
store i32 -1, i32* %4
br label %115
82: ; preds = %72
br label %83
83: ; preds = %82, %101
%84 = load i32, i32* %12
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%86 = load i32, i32* %11
%87 = add i32 %86, 1
%88 = load i32, i32* @MSG_DONTWAIT
%89 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%90 = call i32 @sendto(i32 %84, i8* %85, i32 %87, i32 %88, %struct.sockaddr* %89, i32 8)
store i32 %90, i32* %13
%91 = load i32, i32* %13
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %102
93: ; preds = %83
%94 = load i64, i64* @errno
%95 = load i64, i64* @EINTR
%96 = icmp eq i64 %94, %95
br i1 %96, label %101, label %97
97: ; preds = %93
%98 = load i64, i64* @errno
%99 = load i64, i64* @EAGAIN
%100 = icmp eq i64 %98, %99
br i1 %100, label %101, label %102
101: ; preds = %97, %93
br label %83
102: ; preds = %97, %83
%103 = load i32, i32* %13
%104 = icmp sgt i32 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %102
br label %112
106: ; preds = %102
%107 = load i64, i64* @errno
%108 = call i8* @strerror(i64 %107)
%109 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %108)
%110 = load i32, i32* %12
%111 = call i32 @close(i32 %110)
store i32 -1, i32* %4
br label %115
112: ; preds = %105
%113 = load i32, i32* %12
%114 = call i32 @close(i32 %113)
store i32 0, i32* %4
br label %115
115: ; preds = %112, %106, %78, %71
%116 = load i32, i32* %4
ret i32 %116
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"%s [%d]\00"
@.str.1 = [12 x i8] c"%s info: %s\00"
@.str.2 = [13 x i8] c"%s error: %s\00"
@.str.3 = [16 x i8] c"%s critical: %s\00"
@stderr = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@AF_UNIX = global i32 0
@.str.5 = [9 x i8] c"/dev/log\00"
@SOCK_DGRAM = global i32 0
@.str.6 = [25 x i8] c"devlog socket error: %s\0A\00"
@errno = global i64 0
@MSG_DONTWAIT = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.7 = [19 x i8] c"devlog sendto: %s\0A\00"
define i32 @logmsg(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [64 x i8]
%6 = alloca %struct.sockaddr_un
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = bitcast %struct.sockaddr_un* %6 to i8*
%10 = icmp eq i8* %0, null
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = tail call i8* (...) @eslib_proc_getname()
%13 = tail call i8* (...) @getpid()
%14 = call i32 @eslib_string_sprintf(i8* %8, i32 64, i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
br label %18
15: ; preds = %3
%16 = tail call i8* (...) @getpid()
%17 = call i32 @eslib_string_sprintf(i8* %8, i32 64, i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %16)
br label %18
18: ; preds = %15, %11
%19 = icmp eq i8* %1, null
%20 = select i1 %19, i8* %8, i8* %1
%21 = icmp eq i32 %2, 2
%22 = select i1 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%23 = icmp eq i32 %2, 3
%24 = select i1 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %22
%25 = call i32 @eslib_string_sprintf(i8* %7, i32 1024, i32* null, i8* %24, i8* %8, i8* %20)
%26 = call i32 @strnlen(i8* %7, i32 1024)
%27 = icmp ult i32 %26, 1023
%28 = select i1 %27, i32 %26, i32 1023
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* %7)
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 8)
%36 = load i32, i32* @AF_UNIX
%37 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i64 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i64 @eslib_string_copy(i32 %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 4, i32* null)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %76
42: ; preds = %18
%43 = load i32, i32* @AF_UNIX
%44 = load i32, i32* @SOCK_DGRAM
%45 = call i32 @socket(i32 %43, i32 %44, i32 0)
%46 = icmp eq i32 %45, -1
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = add nuw nsw i32 %28, 1
%49 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
br label %54
50: ; preds = %42
%51 = load i64, i64* @errno
%52 = call i8* @strerror(i64 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %52)
br label %76
54: ; preds = %47, %58
%55 = load i32, i32* @MSG_DONTWAIT
%56 = call i32 @sendto(i32 %45, i8* %7, i32 %48, i32 %55, %struct.sockaddr* %49, i32 8)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %65
58: ; preds = %54
%59 = load i64, i64* @errno
%60 = load i64, i64* @EINTR
%61 = icmp eq i64 %59, %60
%62 = load i64, i64* @EAGAIN
%63 = icmp eq i64 %59, %62
%64 = select i1 %61, i1 true, i1 %63
br i1 %64, label %54, label %69
65: ; preds = %54
%66 = icmp sgt i32 %56, 0
br i1 %66, label %74, label %67
67: ; preds = %65
%68 = load i64, i64* @errno
br label %69
69: ; preds = %58, %67
%70 = phi i64 [ %68, %67 ], [ %59, %58 ]
%71 = call i8* @strerror(i64 %70)
%72 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = call i32 @close(i32 %45)
br label %76
74: ; preds = %65
%75 = call i32 @close(i32 %45)
br label %76
76: ; preds = %69, %18, %74, %50
%77 = phi i32 [ -1, %50 ], [ 0, %74 ], [ -1, %18 ], [ -1, %69 ]
ret i32 %77
}