#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 {
  char *sun_path;
  unsigned char *msg_control;
  int msg_iovlen;
  void *msg_controllen;
  struct iovec *msg_iov;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
struct msghdr {
  char *sun_path;
  unsigned char *msg_control;
  int msg_iovlen;
  void *msg_controllen;
  struct iovec *msg_iov;
  int /*<<< orphan*/ sun_family;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
struct cmsghdr {
  int /*<<< orphan*/ cmsg_type;
  int /*<<< orphan*/ cmsg_level;
  void *cmsg_len;
};
typedef int off_t;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
scalar_t__ CMSG_DATA(struct cmsghdr *);
struct cmsghdr *CMSG_FIRSTHDR(struct sockaddr_un *);
void *CMSG_LEN(int);
int CMSG_SPACE(int);
int /*<<< orphan*/ SCM_RIGHTS;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int sendmsg(int, struct sockaddr_un *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strrchr(char *, char);
int /*<<< orphan*/ write(int, char *, int);
int clamd_fdscan(int fd, char *soname, char *name, size_t len) {
  struct sockaddr_un addr;
  struct msghdr msg;
  struct cmsghdr *cmsg;
  unsigned char fdbuf[CMSG_SPACE(sizeof(int))];
  FILE *sp;
  char buf[256], *p, *q;
  off_t pos;
  int s;
  struct iovec iov[1];
  iov[0].iov_base = "";
  iov[0].iov_len = 1;
  pos = lseek(fd, 0, SEEK_CUR);
  s = socket(AF_UNIX, SOCK_STREAM, 0);
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  strlcpy(addr.sun_path, soname, sizeof(addr.sun_path));
  if (connect(s, (struct sockaddr *)&addr, sizeof(addr))) {
    perror("connect");
    return -1;
  }
  memset(&msg, 0, sizeof(msg));
  msg.msg_control = fdbuf;
  msg.msg_iov = iov;
  msg.msg_iovlen = 1;
  msg.msg_controllen = CMSG_LEN(sizeof(int));
  cmsg = CMSG_FIRSTHDR(&msg);
  cmsg->cmsg_len = CMSG_LEN(sizeof(int));
  cmsg->cmsg_level = SOL_SOCKET;
  cmsg->cmsg_type = SCM_RIGHTS;
  *(int *)CMSG_DATA(cmsg) = fd;
  write(s, "FILDES\n", sizeof("FILDES\n") - 1);
  if (sendmsg(s, &msg, 0) == -1) {
    perror("sendmsg");
    close(s);
    return -1;
  }
  sp = fdopen(s, "r");
  fgets(buf, sizeof(buf), sp);
  fclose(sp);
  close(s);
  if (pos != -1)
    lseek(fd, pos, SEEK_SET);
  if ((p = strrchr(buf, ' ')) != NULL) {
    ++p;
    if (!strncmp(p, "OK", 2))
      return 0;
    else if (!strncmp(p, "FOUND", 5)) {
      if (name != NULL) {
        *--p = '\0';
        q = strrchr(buf, ' ') + 1;
        strlcpy(name, q, len);
      }
      return 1;
    } else {
      puts(buf);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<clamd_fdscan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x4,%edi
call   10f0 <CMSG_SPACE@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1e0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x98(%rbp)
lea    0xd86(%rip),%rax
mov    %rax,-0x1d0(%rbp)
movl   $0x1,-0x1c8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <lseek@plt>
mov    %eax,-0x1b4(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x1b8(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   10b0 <memset@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1100 <strlcpy@plt>
mov    -0x1b8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x30,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
je     1340 <clamd_fdscan+0x110>
lea    0xcdb(%rip),%rdi
call   1120 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1d4(%rbp)
jmp    15cc <clamd_fdscan+0x39c>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   10b0 <memset@plt>
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x1d0(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x1,-0x70(%rbp)
mov    $0x4,%edi
call   10e0 <CMSG_LEN@plt>
mov    %rax,-0x68(%rbp)
lea    -0x80(%rbp),%rdi
call   1140 <CMSG_FIRSTHDR@plt>
mov    %rax,-0x88(%rbp)
mov    $0x4,%edi
call   10e0 <CMSG_LEN@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2c3e(%rip),%rax
mov    (%rax),%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2bfb(%rip),%rax
mov    (%rax),%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1e4(%rbp)
mov    -0x88(%rbp),%rdi
call   1060 <CMSG_DATA@plt>
mov    -0x1e4(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x1b8(%rbp),%edi
lea    0xc16(%rip),%rsi
mov    $0x7,%edx
call   1070 <write@plt>
mov    -0x1b8(%rbp),%edi
lea    -0x80(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0xffffffff,%eax
jne    1443 <clamd_fdscan+0x213>
lea    0xbf3(%rip),%rdi
call   1120 <perror@plt>
mov    -0x1b8(%rbp),%edi
call   10c0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1d4(%rbp)
jmp    15cc <clamd_fdscan+0x39c>
mov    -0x1b8(%rbp),%edi
lea    0xbc8(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    $0x100,%esi
call   10d0 <fgets@plt>
mov    -0xa0(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x1b8(%rbp),%edi
call   10c0 <close@plt>
cmpl   $0xffffffff,-0x1b4(%rbp)
je     14af <clamd_fdscan+0x27f>
mov    -0x8(%rbp),%edi
mov    -0x1b4(%rbp),%esi
mov    0x2b18(%rip),%rax
mov    (%rax),%edx
call   10a0 <lseek@plt>
lea    -0x1a0(%rbp),%rdi
mov    $0x20,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x1a8(%rbp)
cmp    $0x0,%rax
je     15bb <clamd_fdscan+0x38b>
mov    -0x1a8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%rdi
lea    0xb29(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    151a <clamd_fdscan+0x2ea>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1d4(%rbp)
jmp    15cc <clamd_fdscan+0x39c>
mov    -0x1a8(%rbp),%rdi
lea    0xaf5(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    15a5 <clamd_fdscan+0x375>
cmpq   $0x0,-0x18(%rbp)
je     158f <clamd_fdscan+0x35f>
mov    -0x1a8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x1a8(%rbp)
movb   $0x0,-0x1(%rax)
lea    -0x1a0(%rbp),%rdi
mov    $0x20,%esi
call   1090 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x1b0(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1b0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1100 <strlcpy@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1d4(%rbp)
jmp    15cc <clamd_fdscan+0x39c>
lea    -0x1a0(%rbp),%rdi
call   1050 <puts@plt>
jmp    15b6 <clamd_fdscan+0x386>
jmp    15bb <clamd_fdscan+0x38b>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x1d4(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clamd_fdscan>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %rcx,-0x40(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rsi,-0x50(%rbp)
mov    %edi,%r14d
mov    $0x4,%edi
call   10f0 <CMSG_SPACE@plt>
mov    %rsp,-0x30(%rbp)
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xd94(%rip),%rax
mov    %rax,-0x60(%rbp)
movl   $0x1,-0x58(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   10a0 <lseek@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d35(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%r12d
lea    -0xc0(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   10b0 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,-0x98(%rbp)
mov    -0xc0(%rbp),%rdi
mov    $0x8,%edx
mov    -0x50(%rbp),%rsi
call   1100 <strlcpy@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x30,%edx
call   1130 <connect@plt>
test   %rax,%rax
jne    1495 <clamd_fdscan+0x265>
lea    -0x90(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   10b0 <memset@plt>
mov    %rbx,-0x88(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
movl   $0x1,-0x80(%rbp)
mov    $0x4,%edi
call   10e0 <CMSG_LEN@plt>
mov    %rax,-0x78(%rbp)
mov    %r15,%rdi
call   1140 <CMSG_FIRSTHDR@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   10e0 <CMSG_LEN@plt>
mov    %rax,0x8(%rbx)
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    %rbx,%rdi
call   1060 <CMSG_DATA@plt>
mov    %r14d,(%rax)
lea    0xc84(%rip),%rsi
mov    %r12d,%edi
mov    $0x7,%edx
call   1070 <write@plt>
mov    %r12d,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0xffffffff,%eax
je     14a3 <clamd_fdscan+0x273>
lea    0xc6a(%rip),%rsi
mov    %r12d,%edi
call   1110 <fdopen@plt>
mov    %rax,%rbx
lea    -0x1c0(%rbp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   10d0 <fgets@plt>
mov    %rbx,%rdi
call   1080 <fclose@plt>
mov    %r12d,%edi
call   10c0 <close@plt>
mov    -0x34(%rbp),%esi
cmp    $0xffffffff,%esi
je     13f6 <clamd_fdscan+0x1c6>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   10a0 <lseek@plt>
lea    -0x1c0(%rbp),%rdi
mov    $0x20,%esi
call   1090 <strrchr@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     14bd <clamd_fdscan+0x28d>
mov    %rax,%rbx
lea    0x1(%rax),%r12
lea    0xbf6(%rip),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     145b <clamd_fdscan+0x22b>
lea    0xbe1(%rip),%rsi
mov    %r12,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1460 <clamd_fdscan+0x230>
lea    -0x1c0(%rbp),%rdi
call   1050 <puts@plt>
jmp    14bd <clamd_fdscan+0x28d>
xor    %r14d,%r14d
jmp    14bd <clamd_fdscan+0x28d>
mov    $0x1,%r14d
mov    -0x48(%rbp),%r15
test   %r15,%r15
je     14bd <clamd_fdscan+0x28d>
movb   $0x0,(%rbx)
lea    -0x1c0(%rbp),%rdi
mov    $0x20,%esi
call   1090 <strrchr@plt>
lea    0x1(%rax),%rsi
mov    %r15,%rdi
mov    -0x40(%rbp),%rdx
call   1100 <strlcpy@plt>
jmp    14bd <clamd_fdscan+0x28d>
lea    0xb64(%rip),%rdi
call   1120 <perror@plt>
jmp    14b7 <clamd_fdscan+0x287>
lea    0xb66(%rip),%rdi
call   1120 <perror@plt>
mov    %r12d,%edi
call   10c0 <close@plt>
mov    $0xffffffff,%r14d
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i8*, i32, i8*, %struct.iovec*, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i8*, i8*, i32, i8*, %struct.iovec*, i32 }
%struct.cmsghdr = type { i32, i32, i8* }
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.2 = [8 x i8] c"FILDES\0A\00"
@.str.3 = [8 x i8] c"sendmsg\00"
@.str.4 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c"OK\00"
@.str.6 = [6 x i8] c"FOUND\00"
define i32 @clamd_fdscan(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.sockaddr_un
%11 = alloca %struct.msghdr
%12 = alloca %struct.cmsghdr*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
%16 = alloca [256 x i8]
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca [1 x %struct.iovec]
%22 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%23 = call i32 @CMSG_SPACE(i32 4)
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %13
%26 = alloca i8, i64 %24
store i64 %24, i64* %14
%27 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %21, i64 0, i64 0
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %28
%29 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %21, i64 0, i64 0
%30 = getelementptr inbounds %struct.iovec, %struct.iovec* %29, i32 0, i32 1
store i32 1, i32* %30
%31 = load i32, i32* %6
%32 = load i32, i32* @SEEK_CUR
%33 = call i32 @lseek(i32 %31, i32 0, i32 %32)
store i32 %33, i32* %19
%34 = load i32, i32* @AF_UNIX
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %20
%37 = call i32 @memset(%struct.sockaddr_un* %10, i32 0, i32 48)
%38 = load i32, i32* @AF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 5
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = load i8*, i8** %7
%43 = call i32 @strlcpy(i8* %41, i8* %42, i64 8)
%44 = load i32, i32* %20
%45 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%46 = call i64 @connect(i32 %44, %struct.sockaddr* %45, i32 48)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %4
%49 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %22
br label %136
50: ; preds = %4
%51 = bitcast %struct.msghdr* %11 to %struct.sockaddr_un*
%52 = call i32 @memset(%struct.sockaddr_un* %51, i32 0, i32 48)
%53 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 1
store i8* %26, i8** %53
%54 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %21, i64 0, i64 0
%55 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 4
store %struct.iovec* %54, %struct.iovec** %55
%56 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 2
store i32 1, i32* %56
%57 = call i8* @CMSG_LEN(i32 4)
%58 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 3
store i8* %57, i8** %58
%59 = bitcast %struct.msghdr* %11 to %struct.sockaddr_un*
%60 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.sockaddr_un* %59)
store %struct.cmsghdr* %60, %struct.cmsghdr** %12
%61 = call i8* @CMSG_LEN(i32 4)
%62 = load %struct.cmsghdr*, %struct.cmsghdr** %12
%63 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %62, i32 0, i32 2
store i8* %61, i8** %63
%64 = load i32, i32* @SOL_SOCKET
%65 = load %struct.cmsghdr*, %struct.cmsghdr** %12
%66 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %65, i32 0, i32 1
store i32 %64, i32* %66
%67 = load i32, i32* @SCM_RIGHTS
%68 = load %struct.cmsghdr*, %struct.cmsghdr** %12
%69 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %68, i32 0, i32 0
store i32 %67, i32* %69
%70 = load i32, i32* %6
%71 = load %struct.cmsghdr*, %struct.cmsghdr** %12
%72 = call i64 @CMSG_DATA(%struct.cmsghdr* %71)
%73 = inttoptr i64 %72 to i32*
store i32 %70, i32* %73
%74 = load i32, i32* %20
%75 = call i32 @write(i32 %74, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%76 = load i32, i32* %20
%77 = bitcast %struct.msghdr* %11 to %struct.sockaddr_un*
%78 = call i32 @sendmsg(i32 %76, %struct.sockaddr_un* %77, i32 0)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %84
80: ; preds = %50
%81 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%82 = load i32, i32* %20
%83 = call i32 @close(i32 %82)
store i32 -1, i32* %5
store i32 1, i32* %22
br label %136
84: ; preds = %50
%85 = load i32, i32* %20
%86 = call i32* @fdopen(i32 %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %86, i32** %15
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%88 = load i32*, i32** %15
%89 = call i32 @fgets(i8* %87, i32 256, i32* %88)
%90 = load i32*, i32** %15
%91 = call i32 @fclose(i32* %90)
%92 = load i32, i32* %20
%93 = call i32 @close(i32 %92)
%94 = load i32, i32* %19
%95 = icmp ne i32 %94, -1
br i1 %95, label %96, label %101
96: ; preds = %84
%97 = load i32, i32* %6
%98 = load i32, i32* %19
%99 = load i32, i32* @SEEK_SET
%100 = call i32 @lseek(i32 %97, i32 %98, i32 %99)
br label %101
101: ; preds = %96, %84
%102 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%103 = call i8* @strrchr(i8* %102, i8 signext 32)
store i8* %103, i8** %17
%104 = icmp ne i8* %103, null
br i1 %104, label %105, label %135
105: ; preds = %101
%106 = load i8*, i8** %17
%107 = getelementptr inbounds i8, i8* %106, i32 1
store i8* %107, i8** %17
%108 = load i8*, i8** %17
%109 = call i32 @strncmp(i8* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%110 = icmp ne i32 %109, 0
br i1 %110, label %112, label %111
111: ; preds = %105
store i32 0, i32* %5
store i32 1, i32* %22
br label %136
112: ; preds = %105
%113 = load i8*, i8** %17
%114 = call i32 @strncmp(i8* %113, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%115 = icmp ne i32 %114, 0
br i1 %115, label %130, label %116
116: ; preds = %112
%117 = load i8*, i8** %8
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %129
119: ; preds = %116
%120 = load i8*, i8** %17
%121 = getelementptr inbounds i8, i8* %120, i32 -1
store i8* %121, i8** %17
store i8 0, i8* %121
%122 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%123 = call i8* @strrchr(i8* %122, i8 signext 32)
%124 = getelementptr inbounds i8, i8* %123, i64 1
store i8* %124, i8** %18
%125 = load i8*, i8** %8
%126 = load i8*, i8** %18
%127 = load i64, i64* %9
%128 = call i32 @strlcpy(i8* %125, i8* %126, i64 %127)
br label %129
129: ; preds = %119, %116
store i32 1, i32* %5
store i32 1, i32* %22
br label %136
130: ; preds = %112
%131 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%132 = call i32 @puts(i8* %131)
br label %133
133: ; preds = %130
br label %134
134: ; preds = %133
br label %135
135: ; preds = %134, %101
store i32 -1, i32* %5
store i32 1, i32* %22
br label %136
136: ; preds = %135, %129, %111, %80, %48
%137 = load i8*, i8** %13
%138 = load i32, i32* %5
ret i32 %138
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i8*, i32, i8*, %struct.iovec*, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i8*, i8*, i32, i8*, %struct.iovec*, i32 }
%struct.sockaddr = type { i32 }
%struct.cmsghdr = type { i32, i32, i8* }
@.str = [1 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@SOL_SOCKET = global i32 0
@SCM_RIGHTS = global i32 0
@.str.2 = [8 x i8] c"FILDES\0A\00"
@.str.3 = [8 x i8] c"sendmsg\00"
@.str.4 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c"OK\00"
@.str.6 = [6 x i8] c"FOUND\00"
define i32 @clamd_fdscan(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca %struct.sockaddr_un
%6 = alloca %struct.msghdr
%7 = alloca [256 x i8]
%8 = alloca [1 x %struct.iovec]
%9 = bitcast %struct.sockaddr_un* %5 to i8*
%10 = bitcast %struct.msghdr* %6 to i8*
%11 = tail call i32 @CMSG_SPACE(i32 4)
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = bitcast [1 x %struct.iovec]* %8 to i8*
%17 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %8, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %8, i64 0, i64 0, i32 1
store i32 1, i32* %18
%19 = load i32, i32* @SEEK_CUR
%20 = tail call i32 @lseek(i32 %0, i32 0, i32 %19)
%21 = load i32, i32* @AF_UNIX
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = call i32 @memset(%struct.sockaddr_un* %5, i32 0, i32 48)
%25 = load i32, i32* @AF_UNIX
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 5
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @strlcpy(i8* %28, i8* %1, i64 8)
%30 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%31 = call i64 @connect(i32 %23, %struct.sockaddr* %30, i32 48)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %4
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %86
35: ; preds = %4
%36 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %8, i64 0, i64 0
%37 = bitcast %struct.msghdr* %6 to %struct.sockaddr_un*
%38 = call i32 @memset(%struct.sockaddr_un* %37, i32 0, i32 48)
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 1
store i8* %14, i8** %39
%40 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 4
store %struct.iovec* %36, %struct.iovec** %40
%41 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 2
store i32 1, i32* %41
%42 = call i8* @CMSG_LEN(i32 4)
%43 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 3
store i8* %42, i8** %43
%44 = call %struct.cmsghdr* @CMSG_FIRSTHDR(%struct.sockaddr_un* %37)
%45 = call i8* @CMSG_LEN(i32 4)
%46 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %44, i64 0, i32 2
store i8* %45, i8** %46
%47 = load i32, i32* @SOL_SOCKET
%48 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %44, i64 0, i32 1
store i32 %47, i32* %48
%49 = load i32, i32* @SCM_RIGHTS
%50 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %44, i64 0, i32 0
store i32 %49, i32* %50
%51 = call i64 @CMSG_DATA(%struct.cmsghdr* %44)
%52 = inttoptr i64 %51 to i32*
store i32 %0, i32* %52
%53 = call i32 @write(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%54 = call i32 @sendmsg(i32 %23, %struct.sockaddr_un* %37, i32 0)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %35
%57 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @close(i32 %23)
br label %86
59: ; preds = %35
%60 = call i32* @fdopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @fgets(i8* %15, i32 256, i32* %60)
%62 = call i32 @fclose(i32* %60)
%63 = call i32 @close(i32 %23)
%64 = icmp eq i32 %20, -1
br i1 %64, label %68, label %65
65: ; preds = %59
%66 = load i32, i32* @SEEK_SET
%67 = call i32 @lseek(i32 %0, i32 %20, i32 %66)
br label %68
68: ; preds = %65, %59
%69 = call i8* @strrchr(i8* %15, i8 signext 32)
%70 = icmp eq i8* %69, null
br i1 %70, label %86, label %71
71: ; preds = %68
%72 = getelementptr inbounds i8, i8* %69, i64 1
%73 = call i32 @strncmp(i8* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%74 = icmp eq i32 %73, 0
br i1 %74, label %86, label %75
75: ; preds = %71
%76 = call i32 @strncmp(i8* %72, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %75
%79 = icmp eq i8* %2, null
br i1 %79, label %86, label %80
80: ; preds = %78
store i8 0, i8* %69
%81 = call i8* @strrchr(i8* %15, i8 signext 32)
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = call i32 @strlcpy(i8* %2, i8* %82, i64 %3)
br label %86
84: ; preds = %75
%85 = call i32 @puts(i8* %15)
br label %86
86: ; preds = %68, %84, %78, %80, %71, %56, %33
%87 = phi i32 [ -1, %33 ], [ -1, %56 ], [ 0, %71 ], [ 1, %80 ], [ 1, %78 ], [ -1, %84 ], [ -1, %68 ]
ret i32 %87
}