#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 str_map_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ str_map_value_buf(struct str_map_t *, int, char *, int);
int /*<<< orphan*/ str_printf(char **, int *, char *, ...);
void str_map_flags(struct str_map_t *map, int flags, char *out, int size) {
  int i;
  char *comma = "";
  char temp[200];
  str_printf(&out, &size, "{");
  for (i = 0; i < 32; i++) {
    if (flags & (1 << i)) {
      str_printf(&out, &size, "%s", comma);
      str_map_value_buf(map, 1 << i, temp, sizeof temp);
      str_printf(&out, &size, "%s", temp);
      comma = "|";
    }
  }
  str_printf(&out, &size, "}");
}


x86 assembly (clang, -O0):
<str_map_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xec4(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    0xead(%rip),%rdx
mov    $0x0,%al
call   1030 <str_printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jge    11f9 <str_map_flags+0xd9>
mov    -0xc(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11e6 <str_map_flags+0xc6>
mov    -0x28(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    0xe6a(%rip),%rdx
mov    $0x0,%al
call   1030 <str_printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
lea    -0xf0(%rbp),%rdx
mov    $0xc8,%ecx
call   1040 <str_map_value_buf@plt>
lea    -0xf0(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    0xe2e(%rip),%rdx
mov    $0x0,%al
call   1030 <str_printf@plt>
lea    0xe23(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11eb <str_map_flags+0xcb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1161 <str_map_flags+0x41>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    0xdff(%rip),%rdx
mov    $0x0,%al
call   1030 <str_printf@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_map_flags>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %esi,0x14(%rsp)
mov    %rdi,0x18(%rsp)
mov    %rdx,0x8(%rsp)
mov    %ecx,0x4(%rsp)
lea    0xeb6(%rip),%rdx
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1030 <str_printf@plt>
lea    0xea2(%rip),%rax
xor    %r14d,%r14d
jmp    117a <str_map_flags+0x5a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    $0x20,%r14d
je     11ea <str_map_flags+0xca>
mov    $0x1,%r15d
mov    %r14d,%ecx
shl    %cl,%r15d
mov    0x14(%rsp),%ecx
bt     %r14d,%ecx
jae    1170 <str_map_flags+0x50>
lea    0x8(%rsp),%r12
mov    %r12,%rdi
lea    0x4(%rsp),%r13
mov    %r13,%rsi
lea    0xe5b(%rip),%rbp
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <str_printf@plt>
mov    0x18(%rsp),%rdi
mov    %r15d,%esi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdx
mov    $0xc8,%ecx
call   1040 <str_map_value_buf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <str_printf@plt>
lea    0xe1d(%rip),%rax
jmp    1170 <str_map_flags+0x50>
lea    0xe16(%rip),%rdx
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1030 <str_printf@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.str_map_t = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"{\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [2 x i8] c"}\00"
define void @str_map_flags(%struct.str_map_t* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.str_map_t*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [200 x i8]
store %struct.str_map_t* %0, %struct.str_map_t** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %7, i32* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
br label %13
13: ; preds = %33, %4
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i32, i32* %9
%19 = shl i32 1, %18
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i8*, i8** %10
%24 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %7, i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load %struct.str_map_t*, %struct.str_map_t** %5
%26 = load i32, i32* %9
%27 = shl i32 1, %26
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%29 = call i32 @str_map_value_buf(%struct.str_map_t* %25, i32 %27, i8* %28, i32 200)
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%31 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %7, i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %10
br label %32
32: ; preds = %22, %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %13
36: ; preds = %13
%37 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %7, i32* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.str_map_t = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"{\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [2 x i8] c"}\00"
define void @str_map_flags(%struct.str_map_t* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [200 x i8]
store i8* %2, i8** %5
store i32 %3, i32* %6
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%9 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %5, i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %4, %20
%11 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %4 ], [ %21, %20 ]
%12 = phi i32 [ 0, %4 ], [ %22, %20 ]
%13 = shl nuw i32 1, %12
%14 = and i32 %13, %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %5, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%18 = call i32 @str_map_value_buf(%struct.str_map_t* %0, i32 %13, i8* %8, i32 200)
%19 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %5, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %20
20: ; preds = %10, %16
%21 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %16 ], [ %11, %10 ]
%22 = add nuw nsw i32 %12, 1
%23 = icmp eq i32 %22, 32
br i1 %23, label %24, label %10
24: ; preds = %20
%25 = call i32 (i8**, i32*, i8*, ...) @str_printf(i8** %5, i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}