#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
#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*/,
                                 TYPE_2__ *);
int /*<<< orphan*/ svcerr_noproc(int /*<<< orphan*/ *);
int /*<<< orphan*/ svcerr_systemerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
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);
    do {
      (&get)->tv_sec = (&get)->tv_sec - (&clear)->tv_sec;
      (&get)->tv_usec = (&get)->tv_usec - (&clear)->tv_usec;
      if ((&get)->tv_usec < 0) {
        (&get)->tv_sec--;
        (&get)->tv_usec += 1000000;
      }
    } while (0);
    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, &scum)) {
    svcerr_systemerr(transp);
    syslog(LOG_ERR, "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     125f <spray_service+0x10f>
mov    -0x18(%rbp),%rax
lea    0xe7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,0x2eca(%rip)
lea    0x2ecb(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <svc_sendreply@plt>
jmp    12b0 <spray_service+0x160>
mov    0x2e98(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e8f(%rip)
jmp    12b0 <spray_service+0x160>
lea    0x2e9b(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2e95(%rip),%rax
sub    0x2e7e(%rip),%rax
mov    %rax,0x2e87(%rip)
mov    0x2e79(%rip),%eax
sub    0x2e63(%rip),%eax
mov    %eax,0x2e6d(%rip)
cmpl   $0x0,0x2e66(%rip)
jge    123b <spray_service+0xeb>
mov    0x2e61(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2e56(%rip)
mov    0x2e48(%rip),%eax
add    $0xf4240,%eax
mov    %eax,0x2e3d(%rip)
jmp    1240 <spray_service+0xf0>
mov    0x2e39(%rip),%rax
mov    %rax,0x2e0a(%rip)
mov    0x2e24(%rip),%eax
mov    %eax,0x2df6(%rip)
jmp    126d <spray_service+0x11d>
mov    -0x10(%rbp),%rdi
call   1060 <svcerr_noproc@plt>
jmp    12b0 <spray_service+0x160>
mov    -0x10(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0x2dcc(%rip),%rdx
call   1050 <svc_sendreply@plt>
cmp    $0x0,%eax
jne    12b0 <spray_service+0x160>
mov    -0x10(%rbp),%rdi
call   1040 <svcerr_systemerr@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
call   1070 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spray_service>:
push   %rbx
mov    %rsi,%rbx
mov    (%rdi),%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     117a <spray_service+0x2a>
lea    0xe9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
addl   $0x1,0x2eeb(%rip)
jmp    11fa <spray_service+0xaa>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <svcerr_noproc@plt>
lea    0x2eee(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2ee8(%rip),%rax
sub    0x2ed1(%rip),%rax
mov    %rax,0x2eda(%rip)
mov    0x2ecc(%rip),%ecx
sub    0x2eb6(%rip),%ecx
mov    %ecx,0x2ec0(%rip)
jns    11d1 <spray_service+0x81>
add    $0xffffffffffffffff,%rax
mov    %rax,0x2ebb(%rip)
add    $0xf4240,%ecx
mov    %ecx,0x2ea7(%rip)
mov    %rax,0x2e80(%rip)
lea    0x2e71(%rip),%rdx
mov    %ecx,0x2e6b(%rip)
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <svc_sendreply@plt>
test   %eax,%eax
je     1228 <spray_service+0xd8>
pop    %rbx
ret
movl   $0x0,0x2e5a(%rip)
lea    0x2e5b(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
pop    %rbx
jmp    1050 <svc_sendreply@plt>
mov    %rbx,%rdi
call   1040 <svcerr_systemerr@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
pop    %rbx
jmp    1070 <syslog@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32, i64 }
%struct.timeval = type { i32, i64 }
%struct.svc_req = type { i32 }
@spray_service.scum = internal global %struct.TYPE_5__ 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_ERR = 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 %38 [
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_5__, %struct.TYPE_5__* @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, %struct.TYPE_5__* null)
br label %52
15: ; preds = %2
%16 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i32 0, i32 1)
%17 = add nsw i32 %16, 1
store i32 %17, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i32 0, i32 1)
br label %52
18: ; preds = %2
%19 = call i32 @gettimeofday(%struct.timeval* @spray_service.get, i32 0)
br label %20
20: ; preds = %18
%21 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
%22 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.clear, i32 0, i32 1)
%23 = sub nsw i64 %21, %22
store i64 %23, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
%24 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
%25 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.clear, i32 0, i32 0)
%26 = sub nsw i32 %24, %25
store i32 %26, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
%27 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %20
%30 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
%31 = add nsw i64 %30, -1
store i64 %31, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
%32 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
%33 = add nsw i32 %32, 1000000
store i32 %33, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
br label %34
34: ; preds = %29, %20
br label %35
35: ; preds = %34
%36 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 1)
store i64 %36, i64* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i32 0, i32 0, i32 1)
%37 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i32 0, i32 0)
store i32 %37, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i32 0, i32 0, i32 0)
br label %41
38: ; preds = %2
%39 = load i32*, i32** %4
%40 = call i32 @svcerr_noproc(i32* %39)
br label %52
41: ; preds = %35
%42 = load i32*, i32** %4
%43 = load i64, i64* @xdr_spraycumul
%44 = trunc i64 %43 to i32
%45 = call i32 @svc_sendreply(i32* %42, i32 %44, %struct.TYPE_5__* @spray_service.scum)
%46 = icmp ne i32 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %41
%48 = load i32*, i32** %4
%49 = call i32 @svcerr_systemerr(i32* %48)
%50 = load i32, i32* @LOG_ERR
%51 = call i32 @syslog(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %10, %15, %38, %47, %41
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32, i64 }
%struct.timeval = type { i32, i64 }
%struct.svc_req = type { i32 }
@spray_service.scum = internal global %struct.TYPE_5__ 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_ERR = 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 %33 [
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_5__, %struct.TYPE_5__* @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, %struct.TYPE_5__* null)
br label %39
11: ; preds = %2
%12 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i64 0, i32 1)
%13 = add nsw i32 %12, 1
store i32 %13, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i64 0, i32 1)
br label %39
14: ; preds = %2
%15 = tail call i32 @gettimeofday(%struct.timeval* @spray_service.get, i32 0)
%16 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 1)
%17 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.clear, i64 0, i32 1)
%18 = sub nsw i64 %16, %17
store i64 %18, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 1)
%19 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 0)
%20 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.clear, i64 0, i32 0)
%21 = sub nsw i32 %19, %20
store i32 %21, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = add nsw i64 %18, -1
store i64 %24, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 1)
%25 = add nsw i32 %21, 1000000
store i32 %25, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @spray_service.get, i64 0, i32 0)
br label %26
26: ; preds = %14, %23
%27 = phi i32 [ %21, %14 ], [ %25, %23 ]
%28 = phi i64 [ %18, %14 ], [ %24, %23 ]
store i64 %28, i64* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i64 0, i32 0, i32 1)
store i32 %27, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @spray_service.scum, i64 0, i32 0, i32 0)
%29 = load i64, i64* @xdr_spraycumul
%30 = trunc i64 %29 to i32
%31 = tail call i32 @svc_sendreply(i32* %1, i32 %30, %struct.TYPE_5__* @spray_service.scum)
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %39
33: ; preds = %2
%34 = tail call i32 @svcerr_noproc(i32* %1)
br label %39
35: ; preds = %26
%36 = tail call i32 @svcerr_systemerr(i32* %1)
%37 = load i32, i32* @LOG_ERR
%38 = tail call i32 @syslog(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %7, %11, %33, %35, %26
ret void
}