#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 */

/* Variables and functions */
#define POLLERR 132
#define POLLHUP 131
#define POLLIN 130
#define POLLNVAL 129
#define POLLOUT 128
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
const char *poll_bit_string(int events) {
  static struct {
    int bit;
    const char *name;
  } bitnames[] = {{POLLIN, "POLLIN"},     {POLLOUT, "POLLOUT"},
                  {POLLERR, "POLLERR"},   {POLLHUP, "POLLHUP"},
                  {POLLNVAL, "POLLNVAL"}, {0, NULL}};
  static char buffer[60];
  char sepa = '<';
  int k, len = 0;
  for (k = 0; bitnames[k].bit; ++k) {
    if (events & bitnames[k].bit) {
      buffer[len++] = sepa;
      strcpy(buffer + len, bitnames[k].name);
      len = strlen(buffer);
      sepa = '|';
    }
  }
  buffer[len++] = '>';
  buffer[len] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<poll_bit_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x3c,-0x5(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
lea    0x2ef8(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
je     11e2 <poll_bit_string+0xc2>
mov    -0x4(%rbp),%eax
movslq -0xc(%rbp),%rdx
lea    0x2eda(%rip),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11cf <poll_bit_string+0xaf>
mov    -0x5(%rbp),%dl
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2f20(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movslq -0x10(%rbp),%rax
lea    0x2f12(%rip),%rdi
add    %rax,%rdi
movslq -0xc(%rbp),%rcx
lea    0x2e94(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    0x2eed(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
movb   $0x7c,-0x5(%rbp)
jmp    11d4 <poll_bit_string+0xb4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <poll_bit_string+0x1d>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2eb9(%rip),%rax
movb   $0x3e,(%rax,%rcx,1)
movslq -0x10(%rbp),%rcx
lea    0x2eaa(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e9f(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_bit_string>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   $0x82,%bl
je     122f <poll_bit_string+0x10f>
movb   $0x3c,0x2f0a(%rip)
lea    0x2f03(%rip),%r14
lea    0x2efd(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x7c,%cl
test   $0x80,%bl
je     118a <poll_bit_string+0x6a>
cltq
lea    0x2ed8(%rip),%r14
mov    %cl,(%rax,%r14,1)
lea    (%rax,%r14,1),%rdi
add    $0x1,%rdi
lea    0xe8c(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x7c,%cl
test   $0x84,%bl
je     11ba <poll_bit_string+0x9a>
cltq
lea    0x2ea8(%rip),%r14
mov    %cl,(%rax,%r14,1)
lea    (%rax,%r14,1),%rdi
add    $0x1,%rdi
lea    0xe64(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x7c,%cl
test   $0x83,%bl
je     11ea <poll_bit_string+0xca>
cltq
lea    0x2e78(%rip),%r14
mov    %cl,(%rax,%r14,1)
lea    (%rax,%r14,1),%rdi
add    $0x1,%rdi
lea    0xe3c(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x7c,%cl
test   $0x81,%bl
je     1217 <poll_bit_string+0xf7>
cltq
lea    0x2e48(%rip),%rbx
mov    %cl,(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
lea    0xe15(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2e1f(%rip),%rax
movw   $0x3e,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
mov    $0x3c,%cl
test   $0x80,%bl
jne    115f <poll_bit_string+0x3f>
jmp    118a <poll_bit_string+0x6a>

LLVM IR (-O0):
%struct.anon = type { i32, i8* }
@poll_bit_string.bitnames = internal global [6 x %struct.anon] [%struct.anon { i32 130, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i32 128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0) }, %struct.anon { i32 132, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0) }, %struct.anon { i32 131, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0) }, %struct.anon { i32 129, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0) }, %struct.anon zeroinitializer]
@.str = [7 x i8] c"POLLIN\00"
@.str.1 = [8 x i8] c"POLLOUT\00"
@.str.2 = [8 x i8] c"POLLERR\00"
@.str.3 = [8 x i8] c"POLLHUP\00"
@.str.4 = [9 x i8] c"POLLNVAL\00"
@poll_bit_string.buffer = internal global [60 x i8] zeroinitializer
define i8* @poll_bit_string(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i8 60, i8* %3
store i32 0, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %39, %1
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @poll_bit_string.bitnames, i64 0, i64 %8
%10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %6
%14 = load i32, i32* %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @poll_bit_string.bitnames, i64 0, i64 %16
%18 = getelementptr inbounds %struct.anon, %struct.anon* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %14, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %13
%23 = load i8, i8* %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %26
store i8 %23, i8* %27
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0), i64 %29
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @poll_bit_string.bitnames, i64 0, i64 %32
%34 = getelementptr inbounds %struct.anon, %struct.anon* %33, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = call i32 @strcpy(i8* %30, i8* %35)
%37 = call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
store i32 %37, i32* %5
store i8 124, i8* %3
br label %38
38: ; preds = %22, %13
br label %39
39: ; preds = %38
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %6
42: ; preds = %6
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %45
store i8 62, i8* %46
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %48
store i8 0, i8* %49
ret i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@.str = [7 x i8] c"POLLIN\00"
@.str.1 = [8 x i8] c"POLLOUT\00"
@.str.2 = [8 x i8] c"POLLERR\00"
@.str.3 = [8 x i8] c"POLLHUP\00"
@.str.4 = [9 x i8] c"POLLNVAL\00"
@poll_bit_string.buffer = internal global [60 x i8] zeroinitializer
define i8* @poll_bit_string(i32 %0) {
%2 = and i32 %0, 130
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
store i8 60, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0)
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 1), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
br label %7
7: ; preds = %1, %4
%8 = phi i8 [ 124, %4 ], [ 60, %1 ]
%9 = phi i32 [ %6, %4 ], [ 0, %1 ]
%10 = and i32 %0, 128
%11 = icmp eq i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %7
%13 = add nsw i32 %9, 1
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %14
store i8 %8, i8* %15
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %16
%18 = tail call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
br label %20
20: ; preds = %12, %7
%21 = phi i8 [ 124, %12 ], [ %8, %7 ]
%22 = phi i32 [ %19, %12 ], [ %9, %7 ]
%23 = and i32 %0, 132
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %20
%26 = add nsw i32 %22, 1
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %27
store i8 %21, i8* %28
%29 = sext i32 %26 to i64
%30 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %29
%31 = tail call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
br label %33
33: ; preds = %25, %20
%34 = phi i8 [ 124, %25 ], [ %21, %20 ]
%35 = phi i32 [ %32, %25 ], [ %22, %20 ]
%36 = and i32 %0, 131
%37 = icmp eq i32 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %33
%39 = add nsw i32 %35, 1
%40 = sext i32 %35 to i64
%41 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %40
store i8 %34, i8* %41
%42 = sext i32 %39 to i64
%43 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %42
%44 = tail call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%45 = tail call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
br label %46
46: ; preds = %38, %33
%47 = phi i8 [ 124, %38 ], [ %34, %33 ]
%48 = phi i32 [ %45, %38 ], [ %35, %33 ]
%49 = and i32 %0, 129
%50 = icmp eq i32 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %46
%52 = add nsw i32 %48, 1
%53 = sext i32 %48 to i64
%54 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %53
store i8 %47, i8* %54
%55 = sext i32 %52 to i64
%56 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %55
%57 = tail call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%58 = tail call i32 @strlen(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0))
br label %59
59: ; preds = %51, %46
%60 = phi i32 [ %58, %51 ], [ %48, %46 ]
%61 = add nsw i32 %60, 1
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %62
store i8 62, i8* %63
%64 = sext i32 %61 to i64
%65 = getelementptr inbounds [60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 %64
store i8 0, i8* %65
ret i8* getelementptr inbounds ([60 x i8], [60 x i8]* @poll_bit_string.buffer, i64 0, i64 0)
}