#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ optval;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char **, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ geteuid();
scalar_t__ getuid();
void *htons(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ seteuid(scalar_t__);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  int syslog_sock = 0;
  int syslog_tcp_sock = 0;
  int snmptrap_sock = 0;
  int do_syslog = 0;
  int do_syslog_tcp = 0;
  int do_snmptrap = 0;
  int syslog_fd = -1;
  int syslog_tcp_fd = -1;
  int snmptrap_fd = -1;
  int i;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "--syslog"))
      do_syslog = 1;
    else if (!strcmp(argv[i], "--syslog-tcp"))
      do_syslog_tcp = 1;
    else if (!strcmp(argv[i], "--snmptrap"))
      do_snmptrap = 1;
    else if (!strcmp(argv[i], "--syslog-fd"))
      syslog_fd = atoi(argv[i + 1]);
    else if (!strcmp(argv[i], "--syslog-tcp-fd"))
      syslog_tcp_fd = atoi(argv[i + 1]);
    else if (!strcmp(argv[i], "--snmptrap-fd"))
      snmptrap_fd = atoi(argv[i + 1]);
  }
  if (do_syslog && syslog_fd > 0) {
    if (0 > (syslog_sock = socket(PF_INET, SOCK_DGRAM, 0))) {
      perror("Cannot create UDP socket for syslog");
      exit(1);
    }
    int optval = 1;
    if (0 != setsockopt(syslog_sock, SOL_SOCKET, SO_REUSEADDR, &optval,
                        sizeof(optval))) {
      perror("Cannot set UDP socket for syslog to SO_REUSEADDR");
      exit(1);
    }
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(514);
    addr.sin_addr.s_addr = 0;
    if (0 != bind(syslog_sock, (struct sockaddr *)&addr, sizeof(addr))) {
      perror("Cannot bind UDP socket for syslog to port");
      exit(1);
    }
    if (syslog_sock && syslog_sock != syslog_fd) {
      dup2(syslog_sock, syslog_fd);
      close(syslog_sock);
    }
  }
  if (do_syslog_tcp && syslog_tcp_fd > 0) {
    if (0 > (syslog_tcp_sock = socket(PF_INET, SOCK_STREAM, 0))) {
      perror("Cannot create TCP socket for syslog-tcp");
      exit(1);
    }
    int optval = 1;
    if (0 != setsockopt(syslog_tcp_sock, SOL_SOCKET, SO_REUSEADDR, &optval,
                        sizeof(optval))) {
      perror("Cannot set TCP socket for syslog-tcp to SO_REUSEADDR");
      exit(1);
    }
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(514);
    addr.sin_addr.s_addr = 0;
    if (0 != bind(syslog_tcp_sock, (struct sockaddr *)&addr, sizeof(addr))) {
      perror("Cannot bind TCP socket for syslog-tcp to port");
      exit(1);
    }
    if (syslog_tcp_sock && syslog_tcp_sock != syslog_tcp_fd) {
      dup2(syslog_tcp_sock, syslog_tcp_fd);
      close(syslog_tcp_sock);
    }
  }
  if (do_snmptrap && snmptrap_fd > 0) {
    if (0 > (snmptrap_sock = socket(PF_INET, SOCK_DGRAM, 0))) {
      perror("Cannot create UDP socket for snmptrap");
      exit(1);
    }
    int optval = 1;
    if (0 != setsockopt(snmptrap_sock, SOL_SOCKET, SO_REUSEADDR, &optval,
                        sizeof(optval))) {
      perror("Cannot set UDP socket for snmptrap to SO_REUSEADDR");
      exit(1);
    }
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(162);
    addr.sin_addr.s_addr = 0;
    if (0 != bind(snmptrap_sock, (struct sockaddr *)&addr, sizeof(addr))) {
      perror("Cannot bind UDP socket for snmptrap to port");
      exit(1);
    }
    if (snmptrap_sock && snmptrap_sock != snmptrap_fd) {
      dup2(snmptrap_sock, snmptrap_fd);
      close(snmptrap_sock);
    }
  }
  if (getuid() != geteuid()) {
    if (0 != seteuid(getuid())) {
      perror("Cannot drop priviledges");
      exit(1);
    }
  }
  char *last_slash = argv[0];
  char *scan = argv[0];
  while (*scan) {
    if ((*scan) == '/')
      last_slash = scan + 1;
    scan++;
  }
  char newpath[512];
  bzero(&newpath, 512);
  int len_to_copy = last_slash - argv[0];
  if (len_to_copy >= 512)
    exit(1);
  memcpy(newpath, argv[0], len_to_copy);
  strncpy(newpath + len_to_copy, "mkeventd", 511 - len_to_copy);
  execv(newpath, argv);
  perror("Cannot execute mkeventd");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13e6 <main+0x1d6>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd72(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12a8 <main+0x98>
movl   $0x1,-0x20(%rbp)
jmp    13d3 <main+0x1c3>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd4e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12d5 <main+0xc5>
movl   $0x1,-0x24(%rbp)
jmp    13ce <main+0x1be>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd2e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1302 <main+0xf2>
movl   $0x1,-0x28(%rbp)
jmp    13c9 <main+0x1b9>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd0c(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1341 <main+0x131>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    13c4 <main+0x1b4>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcd9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1380 <main+0x170>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    13bf <main+0x1af>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcaa(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    13ba <main+0x1aa>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    13bf <main+0x1af>
jmp    13c4 <main+0x1b4>
jmp    13c9 <main+0x1b9>
jmp    13ce <main+0x1be>
jmp    13d3 <main+0x1c3>
jmp    13d8 <main+0x1c8>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    126f <main+0x5f>
cmpl   $0x0,-0x20(%rbp)
je     150e <main+0x2fe>
cmpl   $0x0,-0x2c(%rbp)
jle    150e <main+0x2fe>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    1438 <main+0x228>
lea    0xc22(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2b9f(%rip),%rax
mov    (%rax),%esi
mov    0x2b66(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1487 <main+0x277>
lea    0xbf7(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2b52(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x202,%edi
call   1060 <htons@plt>
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     14e0 <main+0x2d0>
lea    0xbcf(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     1509 <main+0x2f9>
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     1509 <main+0x2f9>
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1070 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
jmp    150e <main+0x2fe>
cmpl   $0x0,-0x24(%rbp)
je     1636 <main+0x426>
cmpl   $0x0,-0x30(%rbp)
jle    1636 <main+0x426>
mov    0x2a97(%rip),%rax
mov    (%rax),%edi
mov    0x2a96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    1560 <main+0x350>
lea    0xb79(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x1,-0x5c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2a77(%rip),%rax
mov    (%rax),%esi
mov    0x2a3e(%rip),%rax
mov    (%rax),%edx
lea    -0x5c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     15af <main+0x39f>
lea    0xb52(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2a2a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    $0x202,%edi
call   1060 <htons@plt>
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x78(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1608 <main+0x3f8>
lea    0xb2e(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     1631 <main+0x421>
mov    -0x18(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     1631 <main+0x421>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1070 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    1636 <main+0x426>
cmpl   $0x0,-0x28(%rbp)
je     176a <main+0x55a>
cmpl   $0x0,-0x34(%rbp)
jle    176a <main+0x55a>
mov    0x296f(%rip),%rax
mov    (%rax),%edi
mov    0x297e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    1688 <main+0x478>
lea    0xadc(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x1,-0x7c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x294f(%rip),%rax
mov    (%rax),%esi
mov    0x2916(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     16d7 <main+0x4c7>
lea    0xab3(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2902(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    $0xa2,%edi
call   1060 <htons@plt>
mov    %rax,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x98(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     173c <main+0x52c>
lea    0xa81(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1765 <main+0x555>
mov    -0x1c(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     1765 <main+0x555>
mov    -0x1c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1070 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
jmp    176a <main+0x55a>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %rax,-0x2c0(%rbp)
mov    $0x0,%al
call   1080 <geteuid@plt>
mov    %rax,%rcx
mov    -0x2c0(%rbp),%rax
cmp    %rcx,%rax
je     17ca <main+0x5ba>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %rax,%rdi
call   1130 <seteuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     17c5 <main+0x5b5>
lea    0xa24(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    17ca <main+0x5ba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1832 <main+0x622>
mov    -0xa8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    181b <main+0x60b>
mov    -0xa8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
mov    -0xa8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa8(%rbp)
jmp    17e6 <main+0x5d6>
lea    -0x2b0(%rbp),%rdi
mov    $0x200,%esi
call   10e0 <bzero@plt>
mov    -0xa0(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x2b4(%rbp)
cmpl   $0x200,-0x2b4(%rbp)
jl     1874 <main+0x664>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x2b0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x2b4(%rbp),%edx
call   10b0 <memcpy@plt>
lea    -0x2b0(%rbp),%rdi
movslq -0x2b4(%rbp),%rax
add    %rax,%rdi
mov    $0x1ff,%edx
sub    -0x2b4(%rbp),%edx
lea    0x951(%rip),%rsi
call   1030 <strncpy@plt>
lea    -0x2b0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1110 <execv@plt>
lea    0x926(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     15b2 <main+0x3a2>
mov    %edi,%r15d
movl   $0x0,0x18(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0x1,%r14d
lea    0xdb3(%rip),%rbp
movl   $0xffffffff,0x10(%rsp)
ff
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0x0,0x1c(%rsp)
xor    %r13d,%r13d
jmp    1283 <main+0x73>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%r13d
add    $0x1,%r14
cmp    %r14,%r15
je     1350 <main+0x140>
mov    (%rbx,%r14,8),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1270 <main+0x60>
mov    %r12,%rdi
lea    0xd69(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1310 <main+0x100>
mov    %r12,%rdi
lea    0xd63(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     131d <main+0x10d>
mov    %r12,%rdi
lea    0xd5b(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     132a <main+0x11a>
mov    %r12,%rdi
lea    0xd54(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     133d <main+0x12d>
mov    %r12,%rdi
lea    0xd51(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    1276 <main+0x66>
mov    0x8(%rbx,%r14,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    1276 <main+0x66>
nopl   0x0(%rax,%rax,1)
movl   $0x1,0x1c(%rsp)
jmp    1276 <main+0x66>
movl   $0x1,0x18(%rsp)
jmp    1276 <main+0x66>
mov    0x8(%rbx,%r14,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,0x14(%rsp)
jmp    1276 <main+0x66>
mov    0x8(%rbx,%r14,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,0x10(%rsp)
jmp    1276 <main+0x66>
test   %r13d,%r13d
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15d
mov    0x14(%rsp),%r12d
je     1424 <main+0x214>
test   %r12d,%r12d
jle    1424 <main+0x214>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    0x2c57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     168c <main+0x47c>
mov    %eax,%ebp
movl   $0x1,0x8(%rsp)
mov    0x2c45(%rip),%rax
mov    (%rax),%esi
mov    0x2c0c(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jne    1695 <main+0x485>
mov    0x2c10(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    $0x202,%edi
call   1060 <htons@plt>
mov    %rax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    169e <main+0x48e>
test   %ebp,%ebp
je     1424 <main+0x214>
cmp    %r12d,%ebp
je     1424 <main+0x214>
mov    %ebp,%edi
mov    %r12d,%esi
call   1070 <dup2@plt>
mov    %ebp,%edi
call   1090 <close@plt>
cmpl   $0x0,0x1c(%rsp)
je     14eb <main+0x2db>
test   %r15d,%r15d
jle    14eb <main+0x2db>
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
mov    0x2b80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     16a7 <main+0x497>
mov    %eax,%ebp
movl   $0x1,0x8(%rsp)
mov    0x2b7e(%rip),%rax
mov    (%rax),%esi
mov    0x2b45(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jne    16b0 <main+0x4a0>
mov    0x2b49(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    $0x202,%edi
call   1060 <htons@plt>
mov    %rax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    16b9 <main+0x4a9>
test   %ebp,%ebp
je     14eb <main+0x2db>
cmp    %r15d,%ebp
je     14eb <main+0x2db>
mov    %ebp,%edi
mov    %r15d,%esi
call   1070 <dup2@plt>
mov    %ebp,%edi
call   1090 <close@plt>
cmpl   $0x0,0x18(%rsp)
je     15b2 <main+0x3a2>
test   %r14d,%r14d
jle    15b2 <main+0x3a2>
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
mov    0x2ac9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     16c2 <main+0x4b2>
mov    %eax,%ebp
movl   $0x1,0x8(%rsp)
mov    0x2ab7(%rip),%rax
mov    (%rax),%esi
mov    0x2a7e(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jne    16cb <main+0x4bb>
mov    0x2a82(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    $0xa2,%edi
call   1060 <htons@plt>
mov    %rax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    16d4 <main+0x4c4>
test   %ebp,%ebp
je     15b2 <main+0x3a2>
cmp    %r14d,%ebp
je     15b2 <main+0x3a2>
mov    %ebp,%edi
mov    %r14d,%esi
call   1070 <dup2@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1080 <geteuid@plt>
cmp    %rax,%rbp
je     15e0 <main+0x3d0>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%rdi
call   1130 <seteuid@plt>
test   %rax,%rax
jne    1683 <main+0x473>
mov    (%rbx),%r14
lea    0x1(%r14),%rax
mov    %r14,%rbp
jmp    15f7 <main+0x3e7>
nopl   0x0(%rax)
mov    %rax,%rbp
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
cmp    $0x2f,%cl
je     15f0 <main+0x3e0>
test   %cl,%cl
jne    15f3 <main+0x3e3>
lea    0x20(%rsp),%rdi
mov    $0x200,%esi
call   10e0 <bzero@plt>
sub    %r14,%rbp
cmp    $0x200,%ebp
jge    1679 <main+0x469>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10b0 <memcpy@plt>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
mov    $0x1ff,%edx
sub    %ebp,%edx
lea    0xbb8(%rip),%rsi
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1110 <execv@plt>
lea    0xb92(%rip),%rdi
call   10d0 <perror@plt>
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xb50(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0x9b8(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0x9d3(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0x9fb(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xa1c(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xa3b(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xa67(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xa8c(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xaa9(%rip),%rdi
jmp    16db <main+0x4cb>
lea    0xad3(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"--syslog\00"
@.str.1 = [13 x i8] c"--syslog-tcp\00"
@.str.2 = [11 x i8] c"--snmptrap\00"
@.str.3 = [12 x i8] c"--syslog-fd\00"
@.str.4 = [16 x i8] c"--syslog-tcp-fd\00"
@.str.5 = [14 x i8] c"--snmptrap-fd\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.6 = [36 x i8] c"Cannot create UDP socket for syslog\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.7 = [49 x i8] c"Cannot set UDP socket for syslog to SO_REUSEADDR\00"
@AF_INET = global i8* null
@.str.8 = [42 x i8] c"Cannot bind UDP socket for syslog to port\00"
@SOCK_STREAM = global i32 0
@.str.9 = [40 x i8] c"Cannot create TCP socket for syslog-tcp\00"
@.str.10 = [53 x i8] c"Cannot set TCP socket for syslog-tcp to SO_REUSEADDR\00"
@.str.11 = [46 x i8] c"Cannot bind TCP socket for syslog-tcp to port\00"
@.str.12 = [38 x i8] c"Cannot create UDP socket for snmptrap\00"
@.str.13 = [51 x i8] c"Cannot set UDP socket for snmptrap to SO_REUSEADDR\00"
@.str.14 = [44 x i8] c"Cannot bind UDP socket for snmptrap to port\00"
@.str.15 = [24 x i8] c"Cannot drop priviledges\00"
@.str.16 = [9 x i8] c"mkeventd\00"
@.str.17 = [24 x i8] c"Cannot execute mkeventd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sockaddr_in
%18 = alloca i32
%19 = alloca %struct.sockaddr_in
%20 = alloca i32
%21 = alloca %struct.sockaddr_in
%22 = alloca i8*
%23 = alloca i8*
%24 = alloca [512 x i8]
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
store i32 -1, i32* %14
store i32 1, i32* %15
br label %26
26: ; preds = %111, %2
%27 = load i32, i32* %15
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %114
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %30
store i32 1, i32* %9
br label %110
39: ; preds = %30
%40 = load i8**, i8*** %5
%41 = load i32, i32* %15
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %39
store i32 1, i32* %10
br label %109
48: ; preds = %39
%49 = load i8**, i8*** %5
%50 = load i32, i32* %15
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @strcmp(i8* %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp ne i32 %54, 0
br i1 %55, label %57, label %56
56: ; preds = %48
store i32 1, i32* %11
br label %108
57: ; preds = %48
%58 = load i8**, i8*** %5
%59 = load i32, i32* %15
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @strcmp(i8* %62, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%64 = icmp ne i32 %63, 0
br i1 %64, label %73, label %65
65: ; preds = %57
%66 = load i8**, i8*** %5
%67 = load i32, i32* %15
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %66, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @atoi(i8* %71)
store i32 %72, i32* %12
br label %107
73: ; preds = %57
%74 = load i8**, i8*** %5
%75 = load i32, i32* %15
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 @strcmp(i8* %78, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%80 = icmp ne i32 %79, 0
br i1 %80, label %89, label %81
81: ; preds = %73
%82 = load i8**, i8*** %5
%83 = load i32, i32* %15
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %82, i64 %85
%87 = load i8*, i8** %86
%88 = call i32 @atoi(i8* %87)
store i32 %88, i32* %13
br label %106
89: ; preds = %73
%90 = load i8**, i8*** %5
%91 = load i32, i32* %15
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8*, i8** %90, i64 %92
%94 = load i8*, i8** %93
%95 = call i32 @strcmp(i8* %94, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%96 = icmp ne i32 %95, 0
br i1 %96, label %105, label %97
97: ; preds = %89
%98 = load i8**, i8*** %5
%99 = load i32, i32* %15
%100 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %98, i64 %101
%103 = load i8*, i8** %102
%104 = call i32 @atoi(i8* %103)
store i32 %104, i32* %14
br label %105
105: ; preds = %97, %89
br label %106
106: ; preds = %105, %81
br label %107
107: ; preds = %106, %65
br label %108
108: ; preds = %107, %56
br label %109
109: ; preds = %108, %47
br label %110
110: ; preds = %109, %38
br label %111
111: ; preds = %110
%112 = load i32, i32* %15
%113 = add nsw i32 %112, 1
store i32 %113, i32* %15
br label %26
114: ; preds = %26
%115 = load i32, i32* %9
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %165
117: ; preds = %114
%118 = load i32, i32* %12
%119 = icmp sgt i32 %118, 0
br i1 %119, label %120, label %165
120: ; preds = %117
%121 = load i32, i32* @PF_INET
%122 = load i32, i32* @SOCK_DGRAM
%123 = call i32 @socket(i32 %121, i32 %122, i32 0)
store i32 %123, i32* %6
%124 = icmp sgt i32 0, %123
br i1 %124, label %125, label %128
125: ; preds = %120
%126 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %120
store i32 1, i32* %16
%129 = load i32, i32* %6
%130 = load i32, i32* @SOL_SOCKET
%131 = load i32, i32* @SO_REUSEADDR
%132 = call i64 @setsockopt(i32 %129, i32 %130, i32 %131, i32* %16, i32 4)
%133 = icmp ne i64 0, %132
br i1 %133, label %134, label %137
134: ; preds = %128
%135 = call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%136 = call i32 @exit(i32 1)
unreachable
137: ; preds = %128
%138 = load i8*, i8** @AF_INET
%139 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i8* %138, i8** %139
%140 = call i8* @htons(i32 514)
%141 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
store i8* %140, i8** %141
%142 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%143 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %142, i32 0, i32 0
store i64 0, i64* %143
%144 = load i32, i32* %6
%145 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%146 = call i64 @bind(i32 %144, %struct.sockaddr* %145, i32 24)
%147 = icmp ne i64 0, %146
br i1 %147, label %148, label %151
148: ; preds = %137
%149 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
%150 = call i32 @exit(i32 1)
unreachable
151: ; preds = %137
%152 = load i32, i32* %6
%153 = icmp ne i32 %152, 0
br i1 %153, label %154, label %164
154: ; preds = %151
%155 = load i32, i32* %6
%156 = load i32, i32* %12
%157 = icmp ne i32 %155, %156
br i1 %157, label %158, label %164
158: ; preds = %154
%159 = load i32, i32* %6
%160 = load i32, i32* %12
%161 = call i32 @dup2(i32 %159, i32 %160)
%162 = load i32, i32* %6
%163 = call i32 @close(i32 %162)
br label %164
164: ; preds = %158, %154, %151
br label %165
165: ; preds = %164, %117, %114
%166 = load i32, i32* %10
%167 = icmp ne i32 %166, 0
br i1 %167, label %168, label %216
168: ; preds = %165
%169 = load i32, i32* %13
%170 = icmp sgt i32 %169, 0
br i1 %170, label %171, label %216
171: ; preds = %168
%172 = load i32, i32* @PF_INET
%173 = load i32, i32* @SOCK_STREAM
%174 = call i32 @socket(i32 %172, i32 %173, i32 0)
store i32 %174, i32* %7
%175 = icmp sgt i32 0, %174
br i1 %175, label %176, label %179
176: ; preds = %171
%177 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%178 = call i32 @exit(i32 1)
unreachable
179: ; preds = %171
store i32 1, i32* %18
%180 = load i32, i32* %7
%181 = load i32, i32* @SOL_SOCKET
%182 = load i32, i32* @SO_REUSEADDR
%183 = call i64 @setsockopt(i32 %180, i32 %181, i32 %182, i32* %18, i32 4)
%184 = icmp ne i64 0, %183
br i1 %184, label %185, label %188
185: ; preds = %179
%186 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%187 = call i32 @exit(i32 1)
unreachable
188: ; preds = %179
%189 = load i8*, i8** @AF_INET
%190 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
store i8* %189, i8** %190
%191 = call i8* @htons(i32 514)
%192 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i8* %191, i8** %192
%193 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%194 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %193, i32 0, i32 0
store i64 0, i64* %194
%195 = load i32, i32* %7
%196 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%197 = call i64 @bind(i32 %195, %struct.sockaddr* %196, i32 24)
%198 = icmp ne i64 0, %197
br i1 %198, label %199, label %202
199: ; preds = %188
%200 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.11, i64 0, i64 0))
%201 = call i32 @exit(i32 1)
unreachable
202: ; preds = %188
%203 = load i32, i32* %7
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %215
205: ; preds = %202
%206 = load i32, i32* %7
%207 = load i32, i32* %13
%208 = icmp ne i32 %206, %207
br i1 %208, label %209, label %215
209: ; preds = %205
%210 = load i32, i32* %7
%211 = load i32, i32* %13
%212 = call i32 @dup2(i32 %210, i32 %211)
%213 = load i32, i32* %7
%214 = call i32 @close(i32 %213)
br label %215
215: ; preds = %209, %205, %202
br label %216
216: ; preds = %215, %168, %165
%217 = load i32, i32* %11
%218 = icmp ne i32 %217, 0
br i1 %218, label %219, label %267
219: ; preds = %216
%220 = load i32, i32* %14
%221 = icmp sgt i32 %220, 0
br i1 %221, label %222, label %267
222: ; preds = %219
%223 = load i32, i32* @PF_INET
%224 = load i32, i32* @SOCK_DGRAM
%225 = call i32 @socket(i32 %223, i32 %224, i32 0)
store i32 %225, i32* %8
%226 = icmp sgt i32 0, %225
br i1 %226, label %227, label %230
227: ; preds = %222
%228 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0))
%229 = call i32 @exit(i32 1)
unreachable
230: ; preds = %222
store i32 1, i32* %20
%231 = load i32, i32* %8
%232 = load i32, i32* @SOL_SOCKET
%233 = load i32, i32* @SO_REUSEADDR
%234 = call i64 @setsockopt(i32 %231, i32 %232, i32 %233, i32* %20, i32 4)
%235 = icmp ne i64 0, %234
br i1 %235, label %236, label %239
236: ; preds = %230
%237 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.13, i64 0, i64 0))
%238 = call i32 @exit(i32 1)
unreachable
239: ; preds = %230
%240 = load i8*, i8** @AF_INET
%241 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 2
store i8* %240, i8** %241
%242 = call i8* @htons(i32 162)
%243 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 1
store i8* %242, i8** %243
%244 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%245 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %244, i32 0, i32 0
store i64 0, i64* %245
%246 = load i32, i32* %8
%247 = bitcast %struct.sockaddr_in* %21 to %struct.sockaddr*
%248 = call i64 @bind(i32 %246, %struct.sockaddr* %247, i32 24)
%249 = icmp ne i64 0, %248
br i1 %249, label %250, label %253
250: ; preds = %239
%251 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0))
%252 = call i32 @exit(i32 1)
unreachable
253: ; preds = %239
%254 = load i32, i32* %8
%255 = icmp ne i32 %254, 0
br i1 %255, label %256, label %266
256: ; preds = %253
%257 = load i32, i32* %8
%258 = load i32, i32* %14
%259 = icmp ne i32 %257, %258
br i1 %259, label %260, label %266
260: ; preds = %256
%261 = load i32, i32* %8
%262 = load i32, i32* %14
%263 = call i32 @dup2(i32 %261, i32 %262)
%264 = load i32, i32* %8
%265 = call i32 @close(i32 %264)
br label %266
266: ; preds = %260, %256, %253
br label %267
267: ; preds = %266, %219, %216
%268 = call i64 (...) @getuid()
%269 = call i64 (...) @geteuid()
%270 = icmp ne i64 %268, %269
br i1 %270, label %271, label %279
271: ; preds = %267
%272 = call i64 (...) @getuid()
%273 = call i64 @seteuid(i64 %272)
%274 = icmp ne i64 0, %273
br i1 %274, label %275, label %278
275: ; preds = %271
%276 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.15, i64 0, i64 0))
%277 = call i32 @exit(i32 1)
unreachable
278: ; preds = %271
br label %279
279: ; preds = %278, %267
%280 = load i8**, i8*** %5
%281 = getelementptr inbounds i8*, i8** %280, i64 0
%282 = load i8*, i8** %281
store i8* %282, i8** %22
%283 = load i8**, i8*** %5
%284 = getelementptr inbounds i8*, i8** %283, i64 0
%285 = load i8*, i8** %284
store i8* %285, i8** %23
br label %286
286: ; preds = %298, %279
%287 = load i8*, i8** %23
%288 = load i8, i8* %287
%289 = icmp ne i8 %288, 0
br i1 %289, label %290, label %301
290: ; preds = %286
%291 = load i8*, i8** %23
%292 = load i8, i8* %291
%293 = sext i8 %292 to i32
%294 = icmp eq i32 %293, 47
br i1 %294, label %295, label %298
295: ; preds = %290
%296 = load i8*, i8** %23
%297 = getelementptr inbounds i8, i8* %296, i64 1
store i8* %297, i8** %22
br label %298
298: ; preds = %295, %290
%299 = load i8*, i8** %23
%300 = getelementptr inbounds i8, i8* %299, i32 1
store i8* %300, i8** %23
br label %286
301: ; preds = %286
%302 = bitcast [512 x i8]* %24 to i8**
%303 = call i32 @bzero(i8** %302, i32 512)
%304 = load i8*, i8** %22
%305 = load i8**, i8*** %5
%306 = getelementptr inbounds i8*, i8** %305, i64 0
%307 = load i8*, i8** %306
%308 = ptrtoint i8* %304 to i64
%309 = ptrtoint i8* %307 to i64
%310 = sub i64 %308, %309
%311 = trunc i64 %310 to i32
store i32 %311, i32* %25
%312 = load i32, i32* %25
%313 = icmp sge i32 %312, 512
br i1 %313, label %314, label %316
314: ; preds = %301
%315 = call i32 @exit(i32 1)
unreachable
316: ; preds = %301
%317 = getelementptr inbounds [512 x i8], [512 x i8]* %24, i64 0, i64 0
%318 = load i8**, i8*** %5
%319 = getelementptr inbounds i8*, i8** %318, i64 0
%320 = load i8*, i8** %319
%321 = load i32, i32* %25
%322 = call i32 @memcpy(i8* %317, i8* %320, i32 %321)
%323 = getelementptr inbounds [512 x i8], [512 x i8]* %24, i64 0, i64 0
%324 = load i32, i32* %25
%325 = sext i32 %324 to i64
%326 = getelementptr inbounds i8, i8* %323, i64 %325
%327 = load i32, i32* %25
%328 = sub nsw i32 511, %327
%329 = call i32 @strncpy(i8* %326, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0), i32 %328)
%330 = getelementptr inbounds [512 x i8], [512 x i8]* %24, i64 0, i64 0
%331 = load i8**, i8*** %5
%332 = call i32 @execv(i8* %330, i8** %331)
%333 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
%334 = load i32, i32* %3
ret i32 %334
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"--syslog\00"
@.str.1 = [13 x i8] c"--syslog-tcp\00"
@.str.2 = [11 x i8] c"--snmptrap\00"
@.str.3 = [12 x i8] c"--syslog-fd\00"
@.str.4 = [16 x i8] c"--syslog-tcp-fd\00"
@.str.5 = [14 x i8] c"--snmptrap-fd\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.6 = [36 x i8] c"Cannot create UDP socket for syslog\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.7 = [49 x i8] c"Cannot set UDP socket for syslog to SO_REUSEADDR\00"
@AF_INET = global i8* null
@.str.8 = [42 x i8] c"Cannot bind UDP socket for syslog to port\00"
@SOCK_STREAM = global i32 0
@.str.9 = [40 x i8] c"Cannot create TCP socket for syslog-tcp\00"
@.str.10 = [53 x i8] c"Cannot set TCP socket for syslog-tcp to SO_REUSEADDR\00"
@.str.11 = [46 x i8] c"Cannot bind TCP socket for syslog-tcp to port\00"
@.str.12 = [38 x i8] c"Cannot create UDP socket for snmptrap\00"
@.str.13 = [51 x i8] c"Cannot set UDP socket for snmptrap to SO_REUSEADDR\00"
@.str.14 = [44 x i8] c"Cannot bind UDP socket for snmptrap to port\00"
@.str.15 = [24 x i8] c"Cannot drop priviledges\00"
@.str.16 = [9 x i8] c"mkeventd\00"
@.str.17 = [24 x i8] c"Cannot execute mkeventd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca [512 x i8]
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %190
11: ; preds = %2
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %55
%14 = phi i64 [ 1, %11 ], [ %62, %55 ]
%15 = phi i32 [ -1, %11 ], [ %61, %55 ]
%16 = phi i32 [ -1, %11 ], [ %60, %55 ]
%17 = phi i32 [ -1, %11 ], [ %59, %55 ]
%18 = phi i32 [ 0, %11 ], [ %58, %55 ]
%19 = phi i32 [ 0, %11 ], [ %57, %55 ]
%20 = phi i32 [ 0, %11 ], [ %56, %55 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %14
%22 = load i8*, i8** %21
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %55, label %25
25: ; preds = %13
%26 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %55, label %28
28: ; preds = %25
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %55, label %31
31: ; preds = %28
%32 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = add nuw nsw i64 %14, 1
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 @atoi(i8* %37)
br label %55
39: ; preds = %31
%40 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = add nuw nsw i64 %14, 1
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = tail call i32 @atoi(i8* %45)
br label %55
47: ; preds = %39
%48 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = add nuw nsw i64 %14, 1
%52 = getelementptr inbounds i8*, i8** %1, i64 %51
%53 = load i8*, i8** %52
%54 = tail call i32 @atoi(i8* %53)
br label %55
55: ; preds = %28, %25, %13, %42, %50, %47, %34
%56 = phi i32 [ %20, %47 ], [ %20, %50 ], [ %20, %42 ], [ %20, %34 ], [ 1, %13 ], [ %20, %25 ], [ %20, %28 ]
%57 = phi i32 [ %19, %47 ], [ %19, %50 ], [ %19, %42 ], [ %19, %34 ], [ %19, %13 ], [ 1, %25 ], [ %19, %28 ]
%58 = phi i32 [ %18, %47 ], [ %18, %50 ], [ %18, %42 ], [ %18, %34 ], [ %18, %13 ], [ %18, %25 ], [ 1, %28 ]
%59 = phi i32 [ %17, %47 ], [ %17, %50 ], [ %17, %42 ], [ %38, %34 ], [ %17, %13 ], [ %17, %25 ], [ %17, %28 ]
%60 = phi i32 [ %16, %47 ], [ %16, %50 ], [ %46, %42 ], [ %16, %34 ], [ %16, %13 ], [ %16, %25 ], [ %16, %28 ]
%61 = phi i32 [ %15, %47 ], [ %54, %50 ], [ %15, %42 ], [ %15, %34 ], [ %15, %13 ], [ %15, %25 ], [ %15, %28 ]
%62 = add nuw nsw i64 %14, 1
%63 = icmp eq i64 %62, %12
br i1 %63, label %64, label %13
64: ; preds = %55
%65 = icmp ne i32 %56, 0
%66 = icmp sgt i32 %59, 0
%67 = select i1 %65, i1 %66, i1 false
br i1 %67, label %68, label %106
68: ; preds = %64
%69 = load i32, i32* @PF_INET
%70 = load i32, i32* @SOCK_DGRAM
%71 = tail call i32 @socket(i32 %69, i32 %70, i32 0)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%75 = tail call i32 @exit(i32 1)
unreachable
76: ; preds = %68
%77 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%78 = load i32, i32* @SOL_SOCKET
%79 = load i32, i32* @SO_REUSEADDR
%80 = call i64 @setsockopt(i32 %71, i32 %78, i32 %79, i32* %3, i32 4)
%81 = icmp eq i64 %80, 0
br i1 %81, label %85, label %82
82: ; preds = %76
%83 = call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %76
%86 = bitcast %struct.sockaddr_in* %4 to i8*
%87 = load i8*, i8** @AF_INET
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %87, i8** %88
%89 = call i8* @htons(i32 514)
%90 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %89, i8** %90
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i64 0, i64* %91
%92 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%93 = call i64 @bind(i32 %71, %struct.sockaddr* %92, i32 24)
%94 = icmp eq i64 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %85
%96 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %85
%99 = icmp eq i32 %71, 0
%100 = icmp eq i32 %71, %59
%101 = select i1 %99, i1 true, i1 %100
br i1 %101, label %105, label %102
102: ; preds = %98
%103 = call i32 @dup2(i32 %71, i32 %59)
%104 = call i32 @close(i32 %71)
br label %105
105: ; preds = %102, %98
br label %106
106: ; preds = %105, %64
%107 = icmp ne i32 %57, 0
%108 = icmp sgt i32 %60, 0
%109 = select i1 %107, i1 %108, i1 false
br i1 %109, label %110, label %148
110: ; preds = %106
%111 = load i32, i32* @PF_INET
%112 = load i32, i32* @SOCK_STREAM
%113 = call i32 @socket(i32 %111, i32 %112, i32 0)
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %110
%116 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %110
%119 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%120 = load i32, i32* @SOL_SOCKET
%121 = load i32, i32* @SO_REUSEADDR
%122 = call i64 @setsockopt(i32 %113, i32 %120, i32 %121, i32* %5, i32 4)
%123 = icmp eq i64 %122, 0
br i1 %123, label %127, label %124
124: ; preds = %118
%125 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%126 = call i32 @exit(i32 1)
unreachable
127: ; preds = %118
%128 = bitcast %struct.sockaddr_in* %6 to i8*
%129 = load i8*, i8** @AF_INET
%130 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i8* %129, i8** %130
%131 = call i8* @htons(i32 514)
%132 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i8* %131, i8** %132
%133 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i64 0, i64* %133
%134 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%135 = call i64 @bind(i32 %113, %struct.sockaddr* %134, i32 24)
%136 = icmp eq i64 %135, 0
br i1 %136, label %140, label %137
137: ; preds = %127
%138 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.11, i64 0, i64 0))
%139 = call i32 @exit(i32 1)
unreachable
140: ; preds = %127
%141 = icmp eq i32 %113, 0
%142 = icmp eq i32 %113, %60
%143 = select i1 %141, i1 true, i1 %142
br i1 %143, label %147, label %144
144: ; preds = %140
%145 = call i32 @dup2(i32 %113, i32 %60)
%146 = call i32 @close(i32 %113)
br label %147
147: ; preds = %144, %140
br label %148
148: ; preds = %147, %106
%149 = icmp ne i32 %58, 0
%150 = icmp sgt i32 %61, 0
%151 = select i1 %149, i1 %150, i1 false
br i1 %151, label %152, label %190
152: ; preds = %148
%153 = load i32, i32* @PF_INET
%154 = load i32, i32* @SOCK_DGRAM
%155 = call i32 @socket(i32 %153, i32 %154, i32 0)
%156 = icmp slt i32 %155, 0
br i1 %156, label %157, label %160
157: ; preds = %152
%158 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0))
%159 = call i32 @exit(i32 1)
unreachable
160: ; preds = %152
%161 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%162 = load i32, i32* @SOL_SOCKET
%163 = load i32, i32* @SO_REUSEADDR
%164 = call i64 @setsockopt(i32 %155, i32 %162, i32 %163, i32* %7, i32 4)
%165 = icmp eq i64 %164, 0
br i1 %165, label %169, label %166
166: ; preds = %160
%167 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.13, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %160
%170 = bitcast %struct.sockaddr_in* %8 to i8*
%171 = load i8*, i8** @AF_INET
%172 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i8* %171, i8** %172
%173 = call i8* @htons(i32 162)
%174 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
store i8* %173, i8** %174
%175 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0, i32 0
store i64 0, i64* %175
%176 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%177 = call i64 @bind(i32 %155, %struct.sockaddr* %176, i32 24)
%178 = icmp eq i64 %177, 0
br i1 %178, label %182, label %179
179: ; preds = %169
%180 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0))
%181 = call i32 @exit(i32 1)
unreachable
182: ; preds = %169
%183 = icmp eq i32 %155, 0
%184 = icmp eq i32 %155, %61
%185 = select i1 %183, i1 true, i1 %184
br i1 %185, label %189, label %186
186: ; preds = %182
%187 = call i32 @dup2(i32 %155, i32 %61)
%188 = call i32 @close(i32 %155)
br label %189
189: ; preds = %186, %182
br label %190
190: ; preds = %2, %189, %148
%191 = call i64 (...) @getuid()
%192 = call i64 (...) @geteuid()
%193 = icmp eq i64 %191, %192
br i1 %193, label %201, label %194
194: ; preds = %190
%195 = call i64 (...) @getuid()
%196 = call i64 @seteuid(i64 %195)
%197 = icmp eq i64 %196, 0
br i1 %197, label %201, label %198
198: ; preds = %194
%199 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.15, i64 0, i64 0))
%200 = call i32 @exit(i32 1)
unreachable
201: ; preds = %194, %190
%202 = load i8*, i8** %1
br label %203
203: ; preds = %209, %201
%204 = phi i8* [ %202, %201 ], [ %210, %209 ]
%205 = phi i8* [ %202, %201 ], [ %211, %209 ]
%206 = load i8, i8* %205
switch i8 %206, label %209 [
i8 0, label %212
i8 47, label %207
]
207: ; preds = %203
%208 = getelementptr inbounds i8, i8* %205, i64 1
br label %209
209: ; preds = %203, %207
%210 = phi i8* [ %208, %207 ], [ %204, %203 ]
%211 = getelementptr inbounds i8, i8* %205, i64 1
br label %203
212: ; preds = %203
%213 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%214 = bitcast [512 x i8]* %9 to i8**
%215 = call i32 @bzero(i8** %214, i32 512)
%216 = ptrtoint i8* %204 to i64
%217 = ptrtoint i8* %202 to i64
%218 = sub i64 %216, %217
%219 = trunc i64 %218 to i32
%220 = icmp sgt i32 %219, 511
br i1 %220, label %221, label %223
221: ; preds = %212
%222 = call i32 @exit(i32 1)
unreachable
223: ; preds = %212
%224 = call i32 @memcpy(i8* %213, i8* %202, i32 %219)
%225 = shl i64 %218, 32
%226 = ashr exact i64 %225, 32
%227 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %226
%228 = sub nsw i32 511, %219
%229 = call i32 @strncpy(i8* %227, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0), i32 %228)
%230 = call i32 @execv(i8* %213, i8** %1)
%231 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
ret i32 0
}