#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 */
typedef int uint8_t;

/* Variables and functions */
scalar_t__ sprintf(char *, char *, char *);
const char *sas_discovery_flags_to_text(uint8_t flags) {
  static char text[128];
  int i = 0;
  text[0] = 0;
  if (flags & (0x01))
    i += sprintf(text, "%s", "IN_PROGRESS");
  if (flags & (0x02)) {
    if (i > 0)
      text[i++] = ',';
    sprintf(text + i, "%s", "DEVICE_CHANGE");
  }
  return text;
}


x86 assembly (clang, -O0):
<sas_discovery_flags_to_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movb   $0x0,0x2f17(%rip)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     115f <sas_discovery_flags_to_text+0x4f>
lea    0x2f01(%rip),%rdi
lea    0xeba(%rip),%rsi
lea    0xeb6(%rip),%rdx
call   1030 <sprintf@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b2 <sas_discovery_flags_to_text+0xa2>
cmpl   $0x0,-0x8(%rbp)
jle    1191 <sas_discovery_flags_to_text+0x81>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
movslq %eax,%rcx
lea    0x2eb3(%rip),%rax
movb   $0x2c,(%rax,%rcx,1)
movslq -0x8(%rbp),%rax
lea    0x2ea4(%rip),%rdi
add    %rax,%rdi
lea    0xe5a(%rip),%rsi
lea    0xe62(%rip),%rdx
call   1030 <sprintf@plt>
lea    0x2e87(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sas_discovery_flags_to_text>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movb   $0x0,0x2f24(%rip)
test   $0x1,%bpl
jne    112c <sas_discovery_flags_to_text+0x1c>
test   $0x2,%bpl
je     117c <sas_discovery_flags_to_text+0x6c>
xor    %eax,%eax
jmp    115d <sas_discovery_flags_to_text+0x4d>
lea    0x2f0d(%rip),%rbx
lea    0xec6(%rip),%rsi
lea    0xec2(%rip),%rdx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
test   $0x2,%bpl
je     117c <sas_discovery_flags_to_text+0x6c>
test   %eax,%eax
jle    115d <sas_discovery_flags_to_text+0x4d>
mov    %eax,%ecx
add    $0x1,%rax
movb   $0x2c,(%rcx,%rbx,1)
cltq
lea    0x2eda(%rip),%rdi
add    %rax,%rdi
lea    0xe90(%rip),%rsi
lea    0xe98(%rip),%rdx
call   1030 <sprintf@plt>
lea    0x2ebd(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@sas_discovery_flags_to_text.text = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"IN_PROGRESS\00"
@.str.2 = [14 x i8] c"DEVICE_CHANGE\00"
define i8* @sas_discovery_flags_to_text(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0)
%4 = load i32, i32* %2
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = call i64 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, %8
%12 = trunc i64 %11 to i32
store i32 %12, i32* %3
br label %13
13: ; preds = %7, %1
%14 = load i32, i32* %2
%15 = and i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 %23
store i8 44, i8* %24
br label %25
25: ; preds = %20, %17
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0), i64 %27
%29 = call i64 @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %25, %13
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0)
}

LLVM IR (-O2):
@sas_discovery_flags_to_text.text = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"IN_PROGRESS\00"
@.str.2 = [14 x i8] c"DEVICE_CHANGE\00"
define i8* @sas_discovery_flags_to_text(i32 %0) {
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0)
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i64 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = and i32 %0, 2
%7 = icmp eq i32 %6, 0
br i1 %7, label %24, label %11
8: ; preds = %1
%9 = and i32 %0, 2
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %18
11: ; preds = %4
%12 = trunc i64 %5 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = add i64 %5, 1
%16 = and i64 %5, 4294967295
%17 = getelementptr inbounds [128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 %16
store i8 44, i8* %17
br label %18
18: ; preds = %8, %14, %11
%19 = phi i64 [ %15, %14 ], [ %5, %11 ], [ 0, %8 ]
%20 = shl i64 %19, 32
%21 = ashr exact i64 %20, 32
%22 = getelementptr inbounds [128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 %21
%23 = tail call i64 @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %8, %18, %4
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sas_discovery_flags_to_text.text, i64 0, i64 0)
}