#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 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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdde(%rip),%rdx
lea    0x2e68(%rip),%rcx
lea    -0x24(%rbp),%r8
call   1060 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     12b5 <main+0xb5>
mov    -0x28(%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,-0x20(%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,-0x20(%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,-0x14(%rbp)
cmpl   $0x0,-0x14(%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    -0x14(%rbp),%edi
lea    -0x2c(%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    -0x14(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%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,-0x1c(%rbp)
jmp    1543 <main+0x343>
mov    -0x10038(%rbp),%rdi
call   1100 <hv_copy_data@plt>
mov    %eax,-0x1c(%rbp)
jmp    1543 <main+0x343>
mov    $0x0,%al
call   1090 <hv_copy_finished@plt>
mov    %eax,-0x1c(%rbp)
jmp    1543 <main+0x343>
mov    $0x0,%al
call   1050 <hv_copy_cancel@plt>
mov    %eax,-0x1c(%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    -0x14(%rbp),%edi
lea    -0x1c(%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 [8192 x i8*]
%14 = alloca %struct.hv_fcopy_hdr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
store i32 0, i32* %10
%15 = load i32, i32* @FCOPY_CURRENT_VERSION
store i32 %15, i32* %12
br label %16
16: ; preds = %30, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt_long(i32 %17, i8** %18, 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* %10)
store i32 %19, i32* %11
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = load i32, i32* %11
switch i32 %22, label %25 [
i32 110, label %23
i32 104, label %24
]
23: ; preds = %21
store i32 0, i32* %9
br label %30
24: ; preds = %21
br label %25
25: ; preds = %21, %24
%26 = load i8**, i8*** %5
%27 = call i32 @print_usage(i8** %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
br label %16
31: ; preds = %16
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = call i64 @daemon(i32 1, i32 0)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i32, i32* @LOG_ERR
%39 = load i32, i32* @errno
%40 = call i32 @strerror(i32 %39)
%41 = call i32 (i32, i8*, i32, ...) @syslog(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %34, %31
%45 = load i32, i32* @LOG_USER
%46 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 %45)
%47 = load i32, i32* @LOG_INFO
%48 = call i32 (...) @getpid()
%49 = call i32 (i32, i8*, i32, ...) @syslog(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @O_RDWR
%51 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %44
%55 = load i32, i32* @LOG_ERR
%56 = load i32, i32* @errno
%57 = load i32, i32* @errno
%58 = call i32 @strerror(i32 %57)
%59 = call i32 (i32, i8*, i32, ...) @syslog(i32 %55, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %56, i32 %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %44
%63 = load i32, i32* %6
%64 = call i32 @write(i32 %63, i32* %12, i32 4)
%65 = sext i32 %64 to i64
%66 = icmp ne i64 %65, 4
br i1 %66, label %67, label %74
67: ; preds = %62
%68 = load i32, i32* @LOG_ERR
%69 = load i32, i32* @errno
%70 = call i32 @strerror(i32 %69)
%71 = call i32 (i32, i8*, i32, ...) @syslog(i32 %68, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %70)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %62
br label %75
75: ; preds = %74, %124
%76 = load i32, i32* %6
%77 = getelementptr inbounds [8192 x i8*], [8192 x i8*]* %13, i64 0, i64 0
%78 = call i32 @pread(i32 %76, i8** %77, i32 8192, i32 0)
store i32 %78, i32* %7
%79 = load i32, i32* %7
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %88
81: ; preds = %75
%82 = load i32, i32* @LOG_ERR
%83 = load i32, i32* @errno
%84 = call i32 @strerror(i32 %83)
%85 = call i32 (i32, i8*, i32, ...) @syslog(i32 %82, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %84)
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %75
%89 = getelementptr inbounds [8192 x i8*], [8192 x i8*]* %13, i64 0, i64 0
%90 = bitcast i8** %89 to %struct.hv_fcopy_hdr*
store %struct.hv_fcopy_hdr* %90, %struct.hv_fcopy_hdr** %14
%91 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %14
%92 = getelementptr inbounds %struct.hv_fcopy_hdr, %struct.hv_fcopy_hdr* %91, i32 0, i32 0
%93 = load i32, i32* %92
switch i32 %93, label %106 [
i32 130, label %94
i32 129, label %98
i32 131, label %102
i32 132, label %104
]
94: ; preds = %88
%95 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %14
%96 = bitcast %struct.hv_fcopy_hdr* %95 to %struct.hv_start_fcopy*
%97 = call i32 @hv_start_fcopy(%struct.hv_start_fcopy* %96)
store i32 %97, i32* %8
br label %112
98: ; preds = %88
%99 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %14
%100 = bitcast %struct.hv_fcopy_hdr* %99 to %struct.hv_do_fcopy*
%101 = call i32 @hv_copy_data(%struct.hv_do_fcopy* %100)
store i32 %101, i32* %8
br label %112
102: ; preds = %88
%103 = call i32 (...) @hv_copy_finished()
store i32 %103, i32* %8
br label %112
104: ; preds = %88
%105 = call i32 (...) @hv_copy_cancel()
store i32 %105, i32* %8
br label %112
106: ; preds = %88
%107 = load i32, i32* @LOG_ERR
%108 = load %struct.hv_fcopy_hdr*, %struct.hv_fcopy_hdr** %14
%109 = getelementptr inbounds %struct.hv_fcopy_hdr, %struct.hv_fcopy_hdr* %108, i32 0, i32 0
%110 = load i32, i32* %109
%111 = call i32 (i32, i8*, i32, ...) @syslog(i32 %107, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %110)
br label %112
112: ; preds = %106, %104, %102, %98, %94
%113 = load i32, i32* %6
%114 = call i32 @pwrite(i32 %113, i32* %8, i32 4, i32 0)
%115 = sext i32 %114 to i64
%116 = icmp ne i64 %115, 4
br i1 %116, label %117, label %124
117: ; preds = %112
%118 = load i32, i32* @LOG_ERR
%119 = load i32, i32* @errno
%120 = call i32 @strerror(i32 %119)
%121 = call i32 (i32, i8*, i32, ...) @syslog(i32 %118, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %120)
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %112
br label %75
}

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
}