#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_2__ TYPE_1__;

/* Type definitions */
struct pollfd {
  scalar_t__ revents;
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};
struct TYPE_2__ {
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};

/* Variables and functions */
int /*<<< orphan*/ EINTR;
int /*<<< orphan*/ _(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(struct pollfd *);
struct pollfd *malloc(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ svc_getreq_poll(struct pollfd *, int);
int svc_max_pollfd;
TYPE_1__ *svc_pollfd;
void svc_run(void) {
  int i;
  for (;;) {
    struct pollfd *my_pollfd;
    if (svc_max_pollfd == 0 && svc_pollfd == NULL)
      return;
    my_pollfd = malloc(sizeof(struct pollfd) * svc_max_pollfd);
    for (i = 0; i < svc_max_pollfd; ++i) {
      my_pollfd[i].fd = svc_pollfd[i].fd;
      my_pollfd[i].events = svc_pollfd[i].events;
      my_pollfd[i].revents = 0;
    }
    switch (i = poll(my_pollfd, svc_max_pollfd, -1)) {
    case -1:
      free(my_pollfd);
      if (errno == EINTR)
        continue;
      perror(_("svc_run: - poll failed"));
      return;
    case 0:
      free(my_pollfd);
      continue;
    default:
      svc_getreq_poll(my_pollfd, i);
      free(my_pollfd);
    }
  }
}


x86 assembly (clang, -O0):
<svc_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e71(%rip),%rax
cmpl   $0x0,(%rax)
jne    118e <svc_run+0x2e>
mov    0x2e59(%rip),%rax
cmpq   $0x0,(%rax)
jne    118e <svc_run+0x2e>
jmp    12ce <svc_run+0x16e>
mov    0x2e4b(%rip),%rax
movslq (%rax),%rax
shl    $0x4,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
jge    122b <svc_run+0xcb>
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%ecx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %ecx,0xc(%rax)
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%ecx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <svc_run+0x4e>
mov    -0x10(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1268 <svc_run+0x108>
jmp    1258 <svc_run+0xf8>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     12a6 <svc_run+0x146>
jmp    12b4 <svc_run+0x154>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%eax
jne    128e <svc_run+0x12e>
jmp    1168 <svc_run+0x8>
lea    0xd6b(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
call   1070 <perror@plt>
jmp    12ce <svc_run+0x16e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1168 <svc_run+0x8>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1080 <svc_getreq_poll@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1168 <svc_run+0x8>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svc_run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e6e(%rip),%r15
mov    (%r15),%ebx
mov    0x2e5c(%rip),%r12
mov    (%r12),%r13
test   %ebx,%ebx
jne    118d <svc_run+0x2d>
test   %r13,%r13
je     129a <svc_run+0x13a>
mov    0x2e34(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
shl    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    1233 <svc_run+0xd3>
mov    %ebx,%eax
cmp    $0x1,%ebx
jne    11c0 <svc_run+0x60>
xor    %ecx,%ecx
jmp    120c <svc_run+0xac>
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %r14,%rsi
add    $0x1c,%rsi
xor    %ecx,%ecx
xchg   %ax,%ax
mov    0x4(%r13,%rcx,8),%edi
mov    %edi,-0x10(%rsi)
mov    0x0(%r13,%rcx,8),%edi
mov    %edi,-0x14(%rsi)
movq   $0x0,-0x1c(%rsi)
mov    0xc(%r13,%rcx,8),%edi
mov    %edi,(%rsi)
mov    0x8(%r13,%rcx,8),%edi
mov    %edi,-0x4(%rsi)
movq   $0x0,-0xc(%rsi)
add    $0x2,%rcx
add    $0x20,%rsi
cmp    %rcx,%rdx
jne    11d0 <svc_run+0x70>
test   $0x1,%al
je     1233 <svc_run+0xd3>
mov    0x4(%r13,%rcx,8),%eax
mov    %rcx,%rdx
shl    $0x4,%rdx
mov    %eax,0xc(%r14,%rdx,1)
mov    0x0(%r13,%rcx,8),%eax
mov    %eax,0x8(%r14,%rdx,1)
movq   $0x0,(%r14,%rdx,1)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
test   %eax,%eax
je     127a <svc_run+0x11a>
cmp    $0xffffffff,%eax
jne    1270 <svc_run+0x110>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%rbp),%eax
je     1282 <svc_run+0x122>
jmp    12a9 <svc_run+0x149>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %eax,%esi
call   1080 <svc_getreq_poll@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%r15),%ebx
mov    (%r12),%r13
test   %ebx,%ebx
jne    11a0 <svc_run+0x40>
test   %r13,%r13
jne    11a0 <svc_run+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd50(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32, i32 }
%struct.pollfd = type { i64, i32, i32 }
@svc_max_pollfd = global i32 0
@svc_pollfd = global %struct.TYPE_2__* null
@errno = global i32 0
@EINTR = global i32 0
@.str = [23 x i8] c"svc_run: - poll failed\00"
define void @svc_run() {
%1 = alloca i32
%2 = alloca %struct.pollfd*
br label %3
3: ; preds = %74, %65, %61, %0
%4 = load i32, i32* @svc_max_pollfd
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load %struct.TYPE_2__*, %struct.TYPE_2__** @svc_pollfd
%8 = icmp eq %struct.TYPE_2__* %7, null
br i1 %8, label %9, label %10
9: ; preds = %6
br label %75
10: ; preds = %6, %3
%11 = load i32, i32* @svc_max_pollfd
%12 = sext i32 %11 to i64
%13 = mul i64 16, %12
%14 = trunc i64 %13 to i32
%15 = call %struct.pollfd* @malloc(i32 %14)
store %struct.pollfd* %15, %struct.pollfd** %2
store i32 0, i32* %1
br label %16
16: ; preds = %48, %10
%17 = load i32, i32* %1
%18 = load i32, i32* @svc_max_pollfd
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %51
20: ; preds = %16
%21 = load %struct.TYPE_2__*, %struct.TYPE_2__** @svc_pollfd
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i64 %23
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = load %struct.pollfd*, %struct.pollfd** %2
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %27, i64 %29
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 2
store i32 %26, i32* %31
%32 = load %struct.TYPE_2__*, %struct.TYPE_2__** @svc_pollfd
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i64 %34
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load %struct.pollfd*, %struct.pollfd** %2
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %38, i64 %40
%42 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %41, i32 0, i32 1
store i32 %37, i32* %42
%43 = load %struct.pollfd*, %struct.pollfd** %2
%44 = load i32, i32* %1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %43, i64 %45
%47 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %46, i32 0, i32 0
store i64 0, i64* %47
br label %48
48: ; preds = %20
%49 = load i32, i32* %1
%50 = add nsw i32 %49, 1
store i32 %50, i32* %1
br label %16
51: ; preds = %16
%52 = load %struct.pollfd*, %struct.pollfd** %2
%53 = load i32, i32* @svc_max_pollfd
%54 = call i32 @poll(%struct.pollfd* %52, i32 %53, i32 -1)
store i32 %54, i32* %1
switch i32 %54, label %68 [
i32 -1, label %55
i32 0, label %65
]
55: ; preds = %51
%56 = load %struct.pollfd*, %struct.pollfd** %2
%57 = call i32 @free(%struct.pollfd* %56)
%58 = load i32, i32* @errno
%59 = load i32, i32* @EINTR
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %55
br label %3
62: ; preds = %55
%63 = call i32 @_(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%64 = call i32 @perror(i32 %63)
br label %75
65: ; preds = %51
%66 = load %struct.pollfd*, %struct.pollfd** %2
%67 = call i32 @free(%struct.pollfd* %66)
br label %3
68: ; preds = %51
%69 = load %struct.pollfd*, %struct.pollfd** %2
%70 = load i32, i32* %1
%71 = call i32 @svc_getreq_poll(%struct.pollfd* %69, i32 %70)
%72 = load %struct.pollfd*, %struct.pollfd** %2
%73 = call i32 @free(%struct.pollfd* %72)
br label %74
74: ; preds = %68
br label %3
75: ; preds = %62, %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32, i32 }
%struct.pollfd = type { i64, i32, i32 }
@svc_max_pollfd = global i32 0
@svc_pollfd = global %struct.TYPE_2__* null
@errno = global i32 0
@EINTR = global i32 0
@.str = [23 x i8] c"svc_run: - poll failed\00"
define void @svc_run() {
%1 = load i32, i32* @svc_max_pollfd
%2 = icmp eq i32 %1, 0
%3 = load %struct.TYPE_2__*, %struct.TYPE_2__** @svc_pollfd
%4 = icmp eq %struct.TYPE_2__* %3, null
%5 = select i1 %2, i1 %4, i1 false
br i1 %5, label %70, label %6
6: ; preds = %0, %64
%7 = phi %struct.TYPE_2__* [ %67, %64 ], [ %3, %0 ]
%8 = phi i32 [ %65, %64 ], [ %1, %0 ]
%9 = shl i32 %8, 4
%10 = tail call %struct.pollfd* @malloc(i32 %9)
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %50
12: ; preds = %6
%13 = zext i32 %8 to i64
%14 = and i64 %13, 1
%15 = icmp eq i32 %8, 1
br i1 %15, label %39, label %16
16: ; preds = %12
%17 = and i64 %13, 4294967294
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %36, %18 ]
%20 = phi i64 [ 0, %16 ], [ %37, %18 ]
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %19, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %19, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %19, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %19, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %19, i32 0
store i64 0, i64* %27
%28 = or i64 %19, 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %28, i32 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %28, i32 2
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %28, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %28, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %28, i32 0
store i64 0, i64* %35
%36 = add nuw nsw i64 %19, 2
%37 = add i64 %20, 2
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %18
39: ; preds = %18, %12
%40 = phi i64 [ 0, %12 ], [ %36, %18 ]
%41 = icmp eq i64 %14, 0
br i1 %41, label %50, label %42
42: ; preds = %39
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %40, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %40, i32 2
store i32 %44, i32* %45
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 %40, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %40, i32 1
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i64 %40, i32 0
store i64 0, i64* %49
br label %50
50: ; preds = %42, %39, %6
%51 = tail call i32 @poll(%struct.pollfd* %10, i32 %8, i32 -1)
switch i32 %51, label %60 [
i32 -1, label %52
i32 0, label %62
]
52: ; preds = %50
%53 = tail call i32 @free(%struct.pollfd* %10)
%54 = load i32, i32* @errno
%55 = load i32, i32* @EINTR
%56 = icmp eq i32 %54, %55
br i1 %56, label %64, label %57
57: ; preds = %52
%58 = tail call i32 @_(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%59 = tail call i32 @perror(i32 %58)
br label %70
60: ; preds = %50
%61 = tail call i32 @svc_getreq_poll(%struct.pollfd* %10, i32 %51)
br label %62
62: ; preds = %50, %60
%63 = tail call i32 @free(%struct.pollfd* %10)
br label %64
64: ; preds = %62, %52
%65 = load i32, i32* @svc_max_pollfd
%66 = icmp eq i32 %65, 0
%67 = load %struct.TYPE_2__*, %struct.TYPE_2__** @svc_pollfd
%68 = icmp eq %struct.TYPE_2__* %67, null
%69 = select i1 %66, i1 %68, i1 false
br i1 %69, label %70, label %6
70: ; preds = %64, %0, %57
ret void
}