#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 fuse_release_in {
  int dummy;
};
struct fuse_read_in {
  int dummy;
};
struct fuse_poll_in {
  int dummy;
};
struct fuse_out_header {
  int member_0;
  int error;
  int /*<<< orphan*/ unique;
};
struct fuse_open_in {
  int dummy;
};
struct fuse_ioctl_in {
  int dummy;
};
struct fuse_interrupt_in {
  int dummy;
};
struct fuse_in_header {
  int opcode;
  int /*<<< orphan*/ unique;
};
typedef int /*<<< orphan*/ out;

/* Variables and functions */
int ENOSYS;
#define FUSE_DESTROY 134
#define FUSE_INTERRUPT 133
#define FUSE_IOCTL 132
#define FUSE_OPEN 131
#define FUSE_POLL 130
#define FUSE_READ 129
#define FUSE_RELEASE 128
size_t cuse_read(struct fuse_in_header *, int);
int /*<<< orphan*/ cuse_write(struct fuse_out_header *);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int pingdev_interrupt(struct fuse_in_header *, struct fuse_interrupt_in *,
                      size_t);
int pingdev_ioctl(struct fuse_in_header *, struct fuse_ioctl_in *, size_t);
int pingdev_open(struct fuse_in_header *, struct fuse_open_in *, size_t);
int pingdev_poll(struct fuse_in_header *, struct fuse_poll_in *, size_t);
int pingdev_read(struct fuse_in_header *, struct fuse_read_in *, size_t);
int pingdev_release(struct fuse_in_header *, struct fuse_release_in *, size_t);
int /*<<< orphan*/ stderr;
void cuse_in() {
  struct {
    struct fuse_in_header h;
    char buf[1024];
  } in;
  size_t r = cuse_read(&in.h, sizeof(in.buf));
  int err;
  switch (in.h.opcode) {
  case FUSE_DESTROY:
    die("cuse destroyed");
  case FUSE_OPEN:
    err = pingdev_open(&in.h, (struct fuse_open_in *)in.buf, r);
    break;
  case FUSE_READ:
    err = pingdev_read(&in.h, (struct fuse_read_in *)in.buf, r);
    break;
  case FUSE_INTERRUPT:
    err = pingdev_interrupt(&in.h, (struct fuse_interrupt_in *)in.buf, r);
    break;
  case FUSE_RELEASE:
    err = pingdev_release(&in.h, (struct fuse_release_in *)in.buf, r);
    break;
  case FUSE_IOCTL:
    err = pingdev_ioctl(&in.h, (struct fuse_ioctl_in *)in.buf, r);
    break;
  case FUSE_POLL:
    err = pingdev_poll(&in.h, (struct fuse_poll_in *)in.buf, r);
    break;
  default:
    fprintf(stderr, "cuse: unhandled opcode %u\n", in.h.opcode);
    err = ENOSYS;
  }
  if (err >= 0) {
    struct fuse_out_header out = {sizeof(out), .error = -err,
                                  .unique = in.h.unique};
    cuse_write(&out);
  }
}


x86 assembly (clang, -O0):
<cuse_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
lea    -0x408(%rbp),%rdi
mov    $0x400,%esi
call   10c0 <cuse_read@plt>
mov    %rax,-0x410(%rbp)
mov    -0x408(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x428(%rbp)
sub    $0x6,%eax
ja     12f7 <cuse_in+0x157>
mov    -0x428(%rbp),%rax
lea    0xe14(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe20(%rip),%rdi
call   10b0 <die@plt>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   1080 <pingdev_open@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   1060 <pingdev_read@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   10a0 <pingdev_interrupt@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   1040 <pingdev_release@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   1050 <pingdev_ioctl@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
lea    -0x408(%rbp),%rdi
lea    -0x408(%rbp),%rsi
add    $0x8,%rsi
mov    -0x410(%rbp),%rdx
call   1030 <pingdev_poll@plt>
mov    %eax,-0x414(%rbp)
jmp    1321 <cuse_in+0x181>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    -0x408(%rbp),%edx
lea    0xd1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jl     135e <cuse_in+0x1be>
movl   $0xc,-0x420(%rbp)
xor    %eax,%eax
sub    -0x414(%rbp),%eax
mov    %eax,-0x41c(%rbp)
mov    -0x404(%rbp),%eax
mov    %eax,-0x418(%rbp)
lea    -0x420(%rbp),%rdi
call   1090 <cuse_write@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cuse_in>:
push   %rbx
sub    $0x420,%rsp
lea    0x18(%rsp),%rdi
mov    $0x400,%esi
call   10c0 <cuse_read@plt>
mov    %rax,%rbx
mov    0x18(%rsp),%edx
lea    -0x80(%rdx),%eax
cmp    $0x6,%eax
ja     11ed <cuse_in+0x4d>
lea    0xe33(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <pingdev_release@plt>
jmp    127b <cuse_in+0xdb>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
jmp    127b <cuse_in+0xdb>
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   1060 <pingdev_read@plt>
jmp    127b <cuse_in+0xdb>
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   1030 <pingdev_poll@plt>
jmp    127b <cuse_in+0xdb>
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   1050 <pingdev_ioctl@plt>
jmp    127b <cuse_in+0xdb>
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   10a0 <pingdev_interrupt@plt>
jmp    127b <cuse_in+0xdb>
lea    0xdb8(%rip),%rdi
call   10b0 <die@plt>
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdi
mov    %rbx,%rdx
call   1080 <pingdev_open@plt>
test   %eax,%eax
js     129f <cuse_in+0xff>
movl   $0xc,0x8(%rsp)
neg    %eax
mov    %eax,0xc(%rsp)
mov    0x1c(%rsp),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1090 <cuse_write@plt>
add    $0x420,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.anon = type { %struct.fuse_in_header, [1024 x i8] }
%struct.fuse_in_header = type { i32, i32 }
%struct.fuse_out_header = type { i32, i32, i32 }
%struct.fuse_open_in = type { i32 }
%struct.fuse_read_in = type { i32 }
%struct.fuse_interrupt_in = type { i32 }
%struct.fuse_release_in = type { i32 }
%struct.fuse_ioctl_in = type { i32 }
%struct.fuse_poll_in = type { i32 }
@.str = [15 x i8] c"cuse destroyed\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"cuse: unhandled opcode %u\0A\00"
@ENOSYS = global i32 0
define void @cuse_in() {
%1 = alloca %struct.anon
%2 = alloca i64
%3 = alloca i32
%4 = alloca %struct.fuse_out_header
%5 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%6 = call i64 @cuse_read(%struct.fuse_in_header* %5, i32 1024)
store i64 %6, i64* %2
%7 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%8 = getelementptr inbounds %struct.fuse_in_header, %struct.fuse_in_header* %7, i32 0, i32 0
%9 = load i32, i32* %8
switch i32 %9, label %54 [
i32 134, label %10
i32 131, label %12
i32 129, label %19
i32 133, label %26
i32 128, label %33
i32 132, label %40
i32 130, label %47
]
10: ; preds = %0
%11 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %0, %10
%13 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%14 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%16 = bitcast i8* %15 to %struct.fuse_open_in*
%17 = load i64, i64* %2
%18 = call i32 @pingdev_open(%struct.fuse_in_header* %13, %struct.fuse_open_in* %16, i64 %17)
store i32 %18, i32* %3
br label %61
19: ; preds = %0
%20 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%21 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%23 = bitcast i8* %22 to %struct.fuse_read_in*
%24 = load i64, i64* %2
%25 = call i32 @pingdev_read(%struct.fuse_in_header* %20, %struct.fuse_read_in* %23, i64 %24)
store i32 %25, i32* %3
br label %61
26: ; preds = %0
%27 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%28 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %28, i64 0, i64 0
%30 = bitcast i8* %29 to %struct.fuse_interrupt_in*
%31 = load i64, i64* %2
%32 = call i32 @pingdev_interrupt(%struct.fuse_in_header* %27, %struct.fuse_interrupt_in* %30, i64 %31)
store i32 %32, i32* %3
br label %61
33: ; preds = %0
%34 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%35 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %35, i64 0, i64 0
%37 = bitcast i8* %36 to %struct.fuse_release_in*
%38 = load i64, i64* %2
%39 = call i32 @pingdev_release(%struct.fuse_in_header* %34, %struct.fuse_release_in* %37, i64 %38)
store i32 %39, i32* %3
br label %61
40: ; preds = %0
%41 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%42 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %42, i64 0, i64 0
%44 = bitcast i8* %43 to %struct.fuse_ioctl_in*
%45 = load i64, i64* %2
%46 = call i32 @pingdev_ioctl(%struct.fuse_in_header* %41, %struct.fuse_ioctl_in* %44, i64 %45)
store i32 %46, i32* %3
br label %61
47: ; preds = %0
%48 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%49 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %49, i64 0, i64 0
%51 = bitcast i8* %50 to %struct.fuse_poll_in*
%52 = load i64, i64* %2
%53 = call i32 @pingdev_poll(%struct.fuse_in_header* %48, %struct.fuse_poll_in* %51, i64 %52)
store i32 %53, i32* %3
br label %61
54: ; preds = %0
%55 = load i32, i32* @stderr
%56 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%57 = getelementptr inbounds %struct.fuse_in_header, %struct.fuse_in_header* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @ENOSYS
store i32 %60, i32* %3
br label %61
61: ; preds = %54, %47, %40, %33, %26, %19, %12
%62 = load i32, i32* %3
%63 = icmp sge i32 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %61
%65 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %4, i32 0, i32 0
store i32 12, i32* %65
%66 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %4, i32 0, i32 1
%67 = load i32, i32* %3
%68 = sub nsw i32 0, %67
store i32 %68, i32* %66
%69 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %4, i32 0, i32 2
%70 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%71 = getelementptr inbounds %struct.fuse_in_header, %struct.fuse_in_header* %70, i32 0, i32 1
%72 = load i32, i32* %71
store i32 %72, i32* %69
%73 = call i32 @cuse_write(%struct.fuse_out_header* %4)
br label %74
74: ; preds = %64, %61
ret void
}

LLVM IR (-O2):
%struct.anon = type { %struct.fuse_in_header, [1024 x i8] }
%struct.fuse_in_header = type { i32, i32 }
%struct.fuse_out_header = type { i32, i32, i32 }
%struct.fuse_open_in = type { i32 }
%struct.fuse_read_in = type { i32 }
%struct.fuse_interrupt_in = type { i32 }
%struct.fuse_release_in = type { i32 }
%struct.fuse_ioctl_in = type { i32 }
%struct.fuse_poll_in = type { i32 }
@.str = [15 x i8] c"cuse destroyed\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"cuse: unhandled opcode %u\0A\00"
@ENOSYS = global i32 0
define void @cuse_in() {
%1 = alloca %struct.anon
%2 = alloca %struct.fuse_out_header
%3 = bitcast %struct.anon* %1 to i8*
%4 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0
%5 = call i64 @cuse_read(%struct.fuse_in_header* %4, i32 1024)
%6 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %34 [
i32 134, label %8
i32 131, label %10
i32 129, label %14
i32 133, label %18
i32 128, label %22
i32 132, label %26
i32 130, label %30
]
8: ; preds = %0
%9 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %0, %8
%11 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%12 = bitcast i8* %11 to %struct.fuse_open_in*
%13 = call i32 @pingdev_open(%struct.fuse_in_header* %4, %struct.fuse_open_in* %12, i64 %5)
br label %38
14: ; preds = %0
%15 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%16 = bitcast i8* %15 to %struct.fuse_read_in*
%17 = call i32 @pingdev_read(%struct.fuse_in_header* %4, %struct.fuse_read_in* %16, i64 %5)
br label %38
18: ; preds = %0
%19 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%20 = bitcast i8* %19 to %struct.fuse_interrupt_in*
%21 = call i32 @pingdev_interrupt(%struct.fuse_in_header* %4, %struct.fuse_interrupt_in* %20, i64 %5)
br label %38
22: ; preds = %0
%23 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%24 = bitcast i8* %23 to %struct.fuse_release_in*
%25 = call i32 @pingdev_release(%struct.fuse_in_header* %4, %struct.fuse_release_in* %24, i64 %5)
br label %38
26: ; preds = %0
%27 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%28 = bitcast i8* %27 to %struct.fuse_ioctl_in*
%29 = call i32 @pingdev_ioctl(%struct.fuse_in_header* %4, %struct.fuse_ioctl_in* %28, i64 %5)
br label %38
30: ; preds = %0
%31 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1, i64 0
%32 = bitcast i8* %31 to %struct.fuse_poll_in*
%33 = call i32 @pingdev_poll(%struct.fuse_in_header* %4, %struct.fuse_poll_in* %32, i64 %5)
br label %38
34: ; preds = %0
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%37 = load i32, i32* @ENOSYS
br label %38
38: ; preds = %34, %30, %26, %22, %18, %14, %10
%39 = phi i32 [ %37, %34 ], [ %33, %30 ], [ %29, %26 ], [ %25, %22 ], [ %21, %18 ], [ %17, %14 ], [ %13, %10 ]
%40 = icmp sgt i32 %39, -1
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = bitcast %struct.fuse_out_header* %2 to i8*
%43 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %2, i64 0, i32 0
store i32 12, i32* %43
%44 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %2, i64 0, i32 1
%45 = sub nsw i32 0, %39
store i32 %45, i32* %44
%46 = getelementptr inbounds %struct.fuse_out_header, %struct.fuse_out_header* %2, i64 0, i32 2
%47 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0, i32 1
%48 = load i32, i32* %47
store i32 %48, i32* %46
%49 = call i32 @cuse_write(%struct.fuse_out_header* %2)
br label %50
50: ; preds = %41, %38
ret void
}