#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 option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ const member_1;
};
struct hv_start_fcopy {
  int dummy;
};
struct hv_fcopy_hdr {
  int operation;
};
struct hv_do_fcopy {
  int dummy;
};

/* Variables and functions */
#define CANCEL_FCOPY 132
#define COMPLETE_FCOPY 131
int /*<<< orphan*/ EXIT_FAILURE;
int FCOPY_CURRENT_VERSION;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ O_RDWR;
#define START_FILE_COPY 130
#define WRITE_TO_FILE 129
scalar_t__ daemon(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt_long(int, char **, char *, struct option *, int *);
int getpid();
int hv_copy_cancel();
int hv_copy_data(struct hv_do_fcopy *);
int hv_copy_finished();
int hv_start_fcopy(struct hv_start_fcopy *);
#define no_argument 128
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int pread(int, char **, int, int /*<<< orphan*/);
int /*<<< orphan*/ print_usage(char **);
int pwrite(int, int *, int, int /*<<< orphan*/);
int strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, ...);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  int fd, fcopy_fd, len;
  int error;
  int daemonize = 1, long_index = 0, opt;
  int version = FCOPY_CURRENT_VERSION;
  char *buffer[4096 * 2];
  struct hv_fcopy_hdr *in_msg;
  static struct option long_options[] = {{"help", no_argument, 0, 'h'},
                                         {"no-daemon", no_argument, 0, 'n'},
                                         {0, 0, 0, 0}};
  while ((opt = getopt_long(argc, argv, "hn", long_options, &long_index)) !=
         -1) {
    switch (opt) {
    case 'n':
      daemonize = 0;
      break;
    case 'h':
    default:
      print_usage(argv);
      exit(EXIT_FAILURE);
    }
  }
  if (daemonize && daemon(1, 0)) {
    syslog(LOG_ERR, "daemon() failed; error: %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  openlog("HV_FCOPY", 0, LOG_USER);
  syslog(LOG_INFO, "HV_FCOPY starting; pid is:%d", getpid());
  fcopy_fd = open("/dev/vmbus/hv_fcopy", O_RDWR);
  if (fcopy_fd < 0) {
    syslog(LOG_ERR, "open /dev/vmbus/hv_fcopy failed; error: %d %s", errno,
           strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((write(fcopy_fd, &version, sizeof(int))) != sizeof(int)) {
    syslog(LOG_ERR, "Registration failed: %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (1) {
    len = pread(fcopy_fd, buffer, (4096 * 2), 0);
    if (len < 0) {
      syslog(LOG_ERR, "pread failed: %s", strerror(errno));
      exit(EXIT_FAILURE);
    }
    in_msg = (struct hv_fcopy_hdr *)buffer;
    switch (in_msg->operation) {
    case START_FILE_COPY:
      error = hv_start_fcopy((struct hv_start_fcopy *)in_msg);
      break;
    case WRITE_TO_FILE:
      error = hv_copy_data((struct hv_do_fcopy *)in_msg);
      break;
    case COMPLETE_FCOPY:
      error = hv_copy_finished();
      break;
    case CANCEL_FCOPY:
      error = hv_copy_cancel();
      break;
    default:
      syslog(LOG_ERR, "Unknown operation: %d", in_msg->operation);
    }
    if (pwrite(fcopy_fd, &error, sizeof(int), 0) != sizeof(int)) {
      syslog(LOG_ERR, "pwrite failed: %s", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdde(%rip),%rdx
lea    0x2e68(%rip),%rcx
lea    -0x28(%rbp),%r8
call   1060 <getopt_long@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     12b5 <main+0xb5>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1003c(%rbp)
sub    $0x68,%eax
je     1294 <main+0x94>
jmp    1274 <main+0x74>
mov    -0x1003c(%rbp),%eax
sub    $0x6e,%eax
jne    1299 <main+0x99>
jmp    1288 <main+0x88>
movl   $0x0,-0x24(%rbp)
jmp    12b0 <main+0xb0>
jmp    1299 <main+0x99>
mov    -0x10(%rbp),%rdi
call   1110 <print_usage@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    1233 <main+0x33>
cmpl   $0x0,-0x24(%rbp)
je     1316 <main+0x116>
mov    $0x1,%edi
xor    %esi,%esi
call   10a0 <daemon@plt>
cmp    $0x0,%rax
je     1316 <main+0x116>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10040(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x10040(%rbp),%edi
mov    %eax,%edx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edx
lea    0xd17(%rip),%rdi
xor    %esi,%esi
call   10e0 <openlog@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10044(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x10044(%rbp),%edi
mov    %eax,%edx
lea    0xcf4(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
lea    0xcfa(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13d1 <main+0x1d1>
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1004c(%rbp)
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10048(%rbp)
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x1004c(%rbp),%edi
mov    -0x10048(%rbp),%edx
mov    %eax,%ecx
lea    0xcbb(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     142f <main+0x22f>
mov    0x2bbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10050(%rbp)
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x10050(%rbp),%edi
mov    %eax,%edx
lea    0xc8b(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    1434 <main+0x234>
mov    -0x18(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1498 <main+0x298>
mov    0x2b52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10054(%rbp)
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x10054(%rbp),%edi
mov    %eax,%edx
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x10030(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff7f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10060(%rbp)
sub    $0x3,%eax
ja     1523 <main+0x323>
mov    -0x10060(%rbp),%rax
lea    0xb2c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10038(%rbp),%rdi
call   1070 <hv_start_fcopy@plt>
mov    %eax,-0x20(%rbp)
jmp    1543 <main+0x343>
mov    -0x10038(%rbp),%rdi
call   1100 <hv_copy_data@plt>
mov    %eax,-0x20(%rbp)
jmp    1543 <main+0x343>
mov    $0x0,%al
call   1090 <hv_copy_finished@plt>
mov    %eax,-0x20(%rbp)
jmp    1543 <main+0x343>
mov    $0x0,%al
call   1050 <hv_copy_cancel@plt>
mov    %eax,-0x20(%rbp)
jmp    1543 <main+0x343>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
mov    -0x10038(%rbp),%rax
mov    (%rax),%edx
lea    0xb92(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10b0 <pwrite@plt>
cltq
cmp    $0x4,%rax
je     15a3 <main+0x3a3>
mov    0x2a47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10064(%rbp)
mov    0x2a58(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x10064(%rbp),%edi
mov    %eax,%edx
lea    0xb56(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    0x2a2c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    1434 <main+0x234>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xor    %ecx,%ecx
lea    0xdeb(%rip),%r14
lea    0x2e75(%rip),%r15
lea    0xc(%rsp),%r12
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1060 <getopt_long@plt>
mov    $0x1,%cl
cmp    $0x6e,%eax
je     1240 <main+0x40>
cmp    $0xffffffff,%eax
jne    1303 <main+0x103>
test   $0x1,%bl
jne    127f <main+0x7f>
mov    $0x1,%edi
xor    %esi,%esi
call   10a0 <daemon@plt>
test   %rax,%rax
jne    13e5 <main+0x1e5>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0xdae(%rip),%rdi
xor    %esi,%esi
call   10e0 <openlog@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd99(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <syslog@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
lea    0xd9b(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
jns    1310 <main+0x110>
mov    0x2cd8(%rip),%rax
mov    (%rax),%ebx
mov    0x2cef(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1120 <strerror@plt>
lea    0xd86(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <syslog@plt>
jmp    1464 <main+0x264>
mov    %r13,%rdi
call   1110 <print_usage@plt>
jmp    1464 <main+0x264>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1405 <main+0x205>
lea    0x10(%rsp),%r14
mov    0x2c78(%rip),%r13
lea    0xd8f(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xcb5(%rip),%rbp
jmp    137a <main+0x17a>
mov    0x0(%r13),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <syslog@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10b0 <pwrite@plt>
cmp    $0x4,%eax
jne    1425 <main+0x225>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
test   %eax,%eax
js     1440 <main+0x240>
mov    0x10(%rsp),%edx
lea    -0x81(%rdx),%eax
cmp    $0x3,%eax
ja     134d <main+0x14d>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %r14,%rdi
call   1100 <hv_copy_data@plt>
mov    %eax,0x4(%rsp)
jmp    1360 <main+0x160>
mov    %r14,%rdi
call   1070 <hv_start_fcopy@plt>
mov    %eax,0x4(%rsp)
jmp    1360 <main+0x160>
xor    %eax,%eax
call   1090 <hv_copy_finished@plt>
mov    %eax,0x4(%rsp)
jmp    1360 <main+0x160>
xor    %eax,%eax
call   1050 <hv_copy_cancel@plt>
mov    %eax,0x4(%rsp)
jmp    1360 <main+0x160>
mov    0x2bc4(%rip),%rax
mov    (%rax),%ebx
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc1f(%rip),%rsi
jmp    1459 <main+0x259>
mov    0x2ba4(%rip),%rax
mov    (%rax),%ebx
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc82(%rip),%rsi
jmp    1459 <main+0x259>
mov    0x0(%r13),%ebx
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xca6(%rip),%rsi
jmp    1459 <main+0x259>
mov    0x0(%r13),%ebx
mov    0x2b85(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc64(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <syslog@plt>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
%struct.hv_fcopy_hdr = type { i32 }
%struct.hv_start_fcopy = type { i32 }
%struct.hv_do_fcopy = type { i32 }
@FCOPY_CURRENT_VERSION = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 110 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [10 x i8] c"no-daemon\00"
@.str.2 = [3 x i8] c"hn\00"
@EXIT_FAILURE = global i32 0
@LOG_ERR = global i32 0
@.str.3 = [27 x i8] c"daemon() failed; error: %s\00"
@errno = global i32 0
@.str.4 = [9 x i8] c"HV_FCOPY\00"
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@.str.5 = [29 x i8] c"HV_FCOPY starting; pid is:%d\00"
@.str.6 = [20 x i8] c"/dev/vmbus/hv_fcopy\00"
@O_RDWR = global i32 0
@.str.7 = [46 x i8] c"open /dev/vmbus/hv_fcopy failed; error: %d %s\00"
@.str.8 = [24 x i8] c"Registration failed: %s\00"
@.str.9 = [17 x i8] c"pread failed: %s\00"
@.str.10 = [22 x i8] c"Unknown operation: %d\00"
@.str.11 = [18 x i8] c"pwrite failed: %s\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 [8192 x i8*]
%15 = alloca %struct.hv_fcopy_hdr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %10
store i32 0, i32* %11
%16 = load i32, i32* @FCOPY_CURRENT_VERSION
store i32 %16, i32* %13
br label %17
17: ; preds = %31, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt_long(i32 %18, i8** %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %11)
store i32 %20, i32* %12
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = load i32, i32* %12
switch i32 %23, label %26 [
i32 110, label %24
i32 104, label %25
]
24: ; preds = %22
store i32 0, i32* %10
br label %31
25: ; preds = %22
br label %26
26: ; preds = %22, %25
%27 = load i8**, i8*** %5
%28 = call i32 @print_usage(i8** %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %24
br label %17
32: ; preds = %17
%33 = load i32, i32* %10
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = call i64 @daemon(i32 1, i32 0)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i32, i32* @LOG_ERR
%40 = load i32, i32* @errno
%41 = call i32 @strerror(i32 %40)
%42 = call i32 (i32, i8*, i32, ...) @syslog(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35, %32
%46 = load i32, i32* @LOG_USER
%47 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 %46)
%48 = load i32, i32* @LOG_INFO
%49 = call i32 (...) @getpid()
%50 = call i32 (i32, i8*, i32, ...) @syslog(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @O_RDWR
%52 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %45
%56 = load i32, i32* @LOG_ERR
%57 = load i32, i32* @errno
%58 = load i32, i32* @errno
%59 = call i32 @strerror(i32 %58)
%60 = call i32 (i32, i8*, i32, ...) @syslog(i32 %56, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %57, i32 %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %45
%64 = load i32, i32* %7
%65 = call i32 @write(i32 %64, i32* %13, i32 4)
%66 = sext i32 %65 to i64
%67 = icmp ne i64 %66, 4
br i1 %67, label %68, label %75
68: ; preds = %63
%69 = load i32, i32* @LOG_ERR
%70 = load i32, i32* @errno
%71 = call i32 @strerror(i32 %70)
%72 = call i32 (i32, i8*, i32, ...) @syslog(i32 %69, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %63
br label %76
76: ; preds = %75, %125
%77 = load i32, i32* %7
%78 = getelementptr inbounds [8192 x i8*], [8192 x i8*]* %14, i64 0, i64 0
%79 = call i32 @pread(i32 %77, i8** %78, i32 8192, i32 0)
store i32 %79, i32* %8
%80 = load i32, i32* %8
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %89
82: ; preds = %76
%83 = load i32, i32* @LOG_ERR
%84 = load i32, i32* @errno
%85 = call i32 @strerror(i32 %84)
%86 = call i32 (i32, i8*, i32, ...) @syslog(i32 %83, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %85)
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %76
%90 = getelementptr inbounds [8192 x i8*], [8192 x i8*]* %14, i64 0, i64 0
%91 = bitcast i8** %90 to %struct.hv_fcopy_hdr*
store %struct.hv_fcopy_hdr* %91, %struct.hv_fcopy_hdr** %15
%92 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %15
%93 = getelementptr inbounds %struct.hv_fcopy_hdr, %struct.hv_fcopy_hdr* %92, i32 0, i32 0
%94 = load i32, i32* %93
switch i32 %94, label %107 [
i32 130, label %95
i32 129, label %99
i32 131, label %103
i32 132, label %105
]
95: ; preds = %89
%96 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %15
%97 = bitcast %struct.hv_fcopy_hdr* %96 to %struct.hv_start_fcopy*
%98 = call i32 @hv_start_fcopy(%struct.hv_start_fcopy* %97)
store i32 %98, i32* %9
br label %113
99: ; preds = %89
%100 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %15
%101 = bitcast %struct.hv_fcopy_hdr* %100 to %struct.hv_do_fcopy*
%102 = call i32 @hv_copy_data(%struct.hv_do_fcopy* %101)
store i32 %102, i32* %9
br label %113
103: ; preds = %89
%104 = call i32 (...) @hv_copy_finished()
store i32 %104, i32* %9
br label %113
105: ; preds = %89
%106 = call i32 (...) @hv_copy_cancel()
store i32 %106, i32* %9
br label %113
107: ; preds = %89
%108 = load i32, i32* @LOG_ERR
%109 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %15
%110 = getelementptr inbounds %struct.hv_fcopy_hdr, %struct.hv_fcopy_hdr* %109, i32 0, i32 0
%111 = load i32, i32* %110
%112 = call i32 (i32, i8*, i32, ...) @syslog(i32 %108, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %111)
br label %113
113: ; preds = %107, %105, %103, %99, %95
%114 = load i32, i32* %7
%115 = call i32 @pwrite(i32 %114, i32* %9, i32 4, i32 0)
%116 = sext i32 %115 to i64
%117 = icmp ne i64 %116, 4
br i1 %117, label %118, label %125
118: ; preds = %113
%119 = load i32, i32* @LOG_ERR
%120 = load i32, i32* @errno
%121 = call i32 @strerror(i32 %120)
%122 = call i32 (i32, i8*, i32, ...) @syslog(i32 %119, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %121)
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %113
br label %76
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
%struct.hv_do_fcopy = type { i32 }
%struct.hv_start_fcopy = type { i32 }
@FCOPY_CURRENT_VERSION = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 104 }, %struct.option { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 110 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [10 x i8] c"no-daemon\00"
@.str.2 = [3 x i8] c"hn\00"
@EXIT_FAILURE = global i32 0
@LOG_ERR = global i32 0
@.str.3 = [27 x i8] c"daemon() failed; error: %s\00"
@errno = global i32 0
@.str.4 = [9 x i8] c"HV_FCOPY\00"
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@.str.5 = [29 x i8] c"HV_FCOPY starting; pid is:%d\00"
@.str.6 = [20 x i8] c"/dev/vmbus/hv_fcopy\00"
@O_RDWR = global i32 0
@.str.7 = [46 x i8] c"open /dev/vmbus/hv_fcopy failed; error: %d %s\00"
@.str.8 = [24 x i8] c"Registration failed: %s\00"
@.str.9 = [17 x i8] c"pread failed: %s\00"
@.str.10 = [22 x i8] c"Unknown operation: %d\00"
@.str.11 = [18 x i8] c"pwrite failed: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8192 x i8*]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
%10 = load i32, i32* @FCOPY_CURRENT_VERSION
store i32 %10, i32* %5
%11 = bitcast [8192 x i8*]* %6 to i8*
br label %12
12: ; preds = %12, %2
%13 = phi i1 [ false, %2 ], [ true, %12 ]
%14 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %4)
switch i32 %14, label %15 [
i32 -1, label %19
i32 110, label %12
]
15: ; preds = %12
%16 = call i32 @print_usage(i8** %1)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
br i1 %13, label %30, label %20
20: ; preds = %19
%21 = call i64 @daemon(i32 1, i32 0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = load i32, i32* @LOG_ERR
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 (i32, i8*, i32, ...) @syslog(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20, %19
%31 = load i32, i32* @LOG_USER
%32 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 %31)
%33 = load i32, i32* @LOG_INFO
%34 = call i32 (...) @getpid()
%35 = call i32 (i32, i8*, i32, ...) @syslog(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @O_RDWR
%37 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %30
%40 = load i32, i32* @LOG_ERR
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 (i32, i8*, i32, ...) @syslog(i32 %40, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %30
%47 = call i32 @write(i32 %37, i32* %5, i32 4)
%48 = icmp eq i32 %47, 4
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = getelementptr inbounds [8192 x i8*], [8192 x i8*]* %6, i64 0, i64 0
%51 = bitcast [8192 x i8*]* %6 to i32*
%52 = bitcast [8192 x i8*]* %6 to %struct.hv_do_fcopy*
%53 = bitcast [8192 x i8*]* %6 to %struct.hv_start_fcopy*
br label %61
54: ; preds = %46
%55 = load i32, i32* @LOG_ERR
%56 = load i32, i32* @errno
%57 = call i32 @strerror(i32 %56)
%58 = call i32 (i32, i8*, i32, ...) @syslog(i32 %55, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %49, %84
%62 = call i32 @pread(i32 %37, i8** %50, i32 8192, i32 0)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %61
%65 = load i32, i32* @LOG_ERR
%66 = load i32, i32* @errno
%67 = call i32 @strerror(i32 %66)
%68 = call i32 (i32, i8*, i32, ...) @syslog(i32 %65, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %61
%72 = load i32, i32* %51
switch i32 %72, label %81 [
i32 130, label %73
i32 129, label %75
i32 131, label %77
i32 132, label %79
]
73: ; preds = %71
%74 = call i32 @hv_start_fcopy(%struct.hv_start_fcopy* %53)
store i32 %74, i32* %3
br label %84
75: ; preds = %71
%76 = call i32 @hv_copy_data(%struct.hv_do_fcopy* %52)
store i32 %76, i32* %3
br label %84
77: ; preds = %71
%78 = call i32 (...) @hv_copy_finished()
store i32 %78, i32* %3
br label %84
79: ; preds = %71
%80 = call i32 (...) @hv_copy_cancel()
store i32 %80, i32* %3
br label %84
81: ; preds = %71
%82 = load i32, i32* @LOG_ERR
%83 = call i32 (i32, i8*, i32, ...) @syslog(i32 %82, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %72)
br label %84
84: ; preds = %81, %79, %77, %75, %73
%85 = call i32 @pwrite(i32 %37, i32* %3, i32 4, i32 0)
%86 = icmp eq i32 %85, 4
br i1 %86, label %61, label %87
87: ; preds = %84
%88 = load i32, i32* @LOG_ERR
%89 = load i32, i32* @errno
%90 = call i32 @strerror(i32 %89)
%91 = call i32 (i32, i8*, i32, ...) @syslog(i32 %88, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %90)
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
}