#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ xdrproc_t;
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct svc_req {
  int rq_proc;
};
struct TYPE_3__ {
  int /*<<< orphan*/ usec;
  int /*<<< orphan*/ sec;
};
struct TYPE_4__ {
  TYPE_1__ clock;
  int /*<<< orphan*/ counter;
};
typedef TYPE_2__ spraycumul;
typedef int /*<<< orphan*/ *caddr_t;
typedef int /*<<< orphan*/ SVCXPRT;

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
#define NULLPROC 131
#define SPRAYPROC_CLEAR 130
#define SPRAYPROC_GET 129
#define SPRAYPROC_SPRAY 128
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ svc_sendreply(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ svcerr_noproc(int /*<<< orphan*/ *);
int /*<<< orphan*/ svcerr_systemerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
scalar_t__ xdr_spraycumul;
scalar_t__ xdr_void;
void spray_service(struct svc_req *rqstp, SVCXPRT *transp) {
  static spraycumul scum;
  static struct timeval clear, get;
  switch (rqstp->rq_proc) {
  case SPRAYPROC_CLEAR:
    scum.counter = 0;
    (void)gettimeofday(&clear, 0);
  case NULLPROC:
    (void)svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
    return;
  case SPRAYPROC_SPRAY:
    scum.counter++;
    return;
  case SPRAYPROC_GET:
    (void)gettimeofday(&get, 0);
    timersub(&get, &clear, &get);
    scum.clock.sec = get.tv_sec;
    scum.clock.usec = get.tv_usec;
    break;
  default:
    svcerr_noproc(transp);
    return;
  }
  if (!svc_sendreply(transp, (xdrproc_t)xdr_spraycumul, (caddr_t)&scum)) {
    svcerr_systemerr(transp);
    syslog(LOG_WARNING, "bad svc_sendreply");
  }
}


x86 assembly (clang, -O0):
<spray_service>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1227 <spray_service+0xc7>
mov    -0x18(%rbp),%rax
lea    0xe6d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,0x2eba(%rip)
lea    0x2eb7(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <svc_sendreply@plt>
jmp    1278 <spray_service+0x118>
mov    0x2e88(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e7f(%rip)
jmp    1278 <spray_service+0x118>
lea    0x2e7f(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x2e71(%rip),%rdx
lea    0x2e62(%rip),%rsi
mov    %rdx,%rdi
call   1080 <timersub@plt>
mov    0x2e60(%rip),%eax
mov    %eax,0x2e46(%rip)
mov    0x2e50(%rip),%eax
mov    %eax,0x2e36(%rip)
jmp    1235 <spray_service+0xd5>
mov    -0x10(%rbp),%rdi
call   1060 <svcerr_noproc@plt>
jmp    1278 <spray_service+0x118>
mov    -0x10(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0x2e0c(%rip),%rdx
call   1050 <svc_sendreply@plt>
cmp    $0x0,%eax
jne    1278 <spray_service+0x118>
mov    -0x10(%rbp),%rdi
call   1040 <svcerr_systemerr@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1070 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spray_service>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rdi),%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     118a <spray_service+0x2a>
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
addl   $0x1,0x2ed8(%rip)
jmp    11e6 <spray_service+0x86>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <svcerr_noproc@plt>
lea    0x2ecc(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x2eb3(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
call   1080 <timersub@plt>
lea    0x2e95(%rip),%rdx
mov    0x2ea2(%rip),%rax
mov    %rax,0x2e87(%rip)
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <svc_sendreply@plt>
test   %eax,%eax
je     1220 <spray_service+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movl   $0x0,0x2e68(%rip)
lea    0x2e65(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <svc_sendreply@plt>
mov    %rbx,%rdi
call   1040 <svcerr_systemerr@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <syslog@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.svc_req = type { i32 }
@spray_service.scum = internal global %struct.TYPE_4__ zeroinitializer
@spray_service.clear = internal global %struct.timeval zeroinitializer
@spray_service.get = internal global %struct.timeval zeroinitializer
@xdr_void = global i64 0
@xdr_spraycumul = global i64 0
@LOG_WARNING = global i32 0
@.str = [18 x i8] c"bad svc_sendreply\00"
define void @spray_service(%struct.svc_req* %0, i32* %1) {
%3 = alloca %struct.svc_req*
%4 = alloca i32*
store %struct.svc_req* %0, %struct.svc_req** %3
store i32* %1, i32** %4
%5 = load %struct.svc_req*, %struct.svc_req** %3
%6 = getelementptr inbounds %struct.svc_req, %struct.svc_req* %5, i32 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %23 [
i32 130, label %8
i32 131, label %10
i32 128, label %15
i32 129, label %18
]
8: ; preds = %2
store i32 0, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 1)
%9 = call i32 @gettimeofday(%struct.timeval* @spray_service.clear, i32 0)
br label %10
10: ; preds = %2, %8
%11 = load i32*, i32** %4
%12 = load i64, i64* @xdr_void
%13 = trunc i64 %12 to i32
%14 = call i32 @svc_sendreply(i32* %11, i32 %13, i32* null)
br label %37
15: ; preds = %2
%16 = load i32, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 1)
%17 = add nsw i32 %16, 1
store i32 %17, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 1)
br label %37
18: ; preds = %2
%19 = call i32 @gettimeofday(%struct.timeval* @spray_service.get, i32 0)
%20 = call i32 @timersub(%struct.timeval* @spray_service.get, %struct.timeval* @spray_service.clear, %struct.timeval* @spray_service.get)
%21 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
store i32 %21, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 0, i32 1)
%22 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
store i32 %22, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 0, i32 0)
br label %26
23: ; preds = %2
%24 = load i32*, i32** %4
%25 = call i32 @svcerr_noproc(i32* %24)
br label %37
26: ; preds = %18
%27 = load i32*, i32** %4
%28 = load i64, i64* @xdr_spraycumul
%29 = trunc i64 %28 to i32
%30 = call i32 @svc_sendreply(i32* %27, i32 %29, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i32 0, i32 0, i32 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %26
%33 = load i32*, i32** %4
%34 = call i32 @svcerr_systemerr(i32* %33)
%35 = load i32, i32* @LOG_WARNING
%36 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %10, %15, %23, %32, %26
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.svc_req = type { i32 }
@spray_service.scum = internal global %struct.TYPE_4__ zeroinitializer
@spray_service.clear = internal global %struct.timeval zeroinitializer
@spray_service.get = internal global %struct.timeval zeroinitializer
@xdr_void = global i64 0
@xdr_spraycumul = global i64 0
@LOG_WARNING = global i32 0
@.str = [18 x i8] c"bad svc_sendreply\00"
define void @spray_service(%struct.svc_req* nocapture %0, i32* %1) {
%3 = getelementptr inbounds %struct.svc_req, %struct.svc_req* %0, i64 0, i32 0
%4 = load i32, i32* %3
switch i32 %4, label %23 [
i32 130, label %5
i32 131, label %7
i32 128, label %11
i32 129, label %14
]
5: ; preds = %2
store i32 0, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 1)
%6 = tail call i32 @gettimeofday(%struct.timeval* @spray_service.clear, i32 0)
br label %7
7: ; preds = %2, %5
%8 = load i64, i64* @xdr_void
%9 = trunc i64 %8 to i32
%10 = tail call i32 @svc_sendreply(i32* %1, i32 %9, i32* null)
br label %29
11: ; preds = %2
%12 = load i32, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 1)
%13 = add nsw i32 %12, 1
store i32 %13, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 1)
br label %29
14: ; preds = %2
%15 = tail call i32 @gettimeofday(%struct.timeval* @spray_service.get, i32 0)
%16 = tail call i32 @timersub(%struct.timeval* @spray_service.get, %struct.timeval* @spray_service.clear, %struct.timeval* @spray_service.get)
%17 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 1)
store i32 %17, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 0, i32 1)
%18 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 0)
store i32 %18, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 0, i32 0)
%19 = load i64, i64* @xdr_spraycumul
%20 = trunc i64 %19 to i32
%21 = tail call i32 @svc_sendreply(i32* %1, i32 %20, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @spray_service.scum, i64 0, i32 0, i32 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %29
23: ; preds = %2
%24 = tail call i32 @svcerr_noproc(i32* %1)
br label %29
25: ; preds = %14
%26 = tail call i32 @svcerr_systemerr(i32* %1)
%27 = load i32, i32* @LOG_WARNING
%28 = tail call i32 @syslog(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %7, %11, %23, %25, %14
ret void
}