#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ virusname;

/* Variables and functions */
int clamd_fdscan(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char virusname[256];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <clamd_socket>\n", argv[0]);
    return 1;
  }
  virusname[0] = 0;
  if (clamd_fdscan(0, argv[1], virusname, sizeof(virusname)) == -1) {
    perror("Error sending fd!");
    return 2;
  } else {
    printf("FOUND: %s\n", virusname);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118b <main+0x4b>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0xa8>
movb   $0x0,-0x110(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x110(%rbp),%rdx
xor    %edi,%edi
mov    $0x100,%ecx
call   1050 <clamd_fdscan@plt>
cmp    $0xffffffff,%eax
jne    11ce <main+0x8e>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11e8 <main+0xa8>
lea    -0x110(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    117c <main+0x3c>
movb   $0x0,(%rsp)
mov    0x8(%rsi),%rsi
xor    %ebx,%ebx
mov    %rsp,%rdx
xor    %edi,%edi
mov    $0x100,%ecx
call   1050 <clamd_fdscan@plt>
cmp    $0xffffffff,%eax
je     11a4 <main+0x64>
lea    0xeba(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
jmp    1199 <main+0x59>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%ebx
jmp    1199 <main+0x59>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <clamd_socket>\0A\00"
@.str.1 = [18 x i8] c"Error sending fd!\00"
@.str.2 = [11 x i8] c"FOUND: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %29
15: ; preds = %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8 0, i8* %16
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32 @clamd_fdscan(i32 0, i8* %19, i8* %20, i32 256)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %29
25: ; preds = %15
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25
store i32 0, i32* %3
br label %29
29: ; preds = %28, %23, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <clamd_socket>\0A\00"
@.str.1 = [18 x i8] c"Error sending fd!\00"
@.str.2 = [11 x i8] c"FOUND: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %19
10: ; preds = %2
store i8 0, i8* %4
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @clamd_fdscan(i32 0, i8* %12, i8* %4, i32 256)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %19
19: ; preds = %17, %15, %6
%20 = phi i32 [ 1, %6 ], [ 2, %15 ], [ 0, %17 ]
ret i32 %20
}