#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 /*<<< orphan*/ u_long;

/* Variables and functions */
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *);
char *fflagstostr(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *flags_to_string(u_long fflags) {
  char *string;
  string = fflagstostr(fflags);
  if (string != NULL && *string == '\0') {
    free(string);
    string = strdup("none");
  }
  if (string == NULL)
    err(1, NULL);
  return string;
}


x86 assembly (clang, -O0):
<flags_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <fflagstostr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <flags_to_string+0x4b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118b <flags_to_string+0x4b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe7e(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <flags_to_string+0x64>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flags_to_string>:
push   %rbx
call   1040 <fflagstostr@plt>
test   %rax,%rax
je     116f <flags_to_string+0x2f>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    117d <flags_to_string+0x3d>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe9e(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <flags_to_string+0x3d>
xor    %ebx,%ebx
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <err@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"none\00"
define i8* @flags_to_string(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i8* @fflagstostr(i32 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @free(i8* %14)
%16 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %3
br label %17
17: ; preds = %13, %8, %1
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @err(i32 1, i32* null)
br label %22
22: ; preds = %20, %17
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"none\00"
define i8* @flags_to_string(i32 %0) {
%2 = tail call i8* @fflagstostr(i32 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i32 @free(i8* %2)
%9 = tail call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1, %7
%12 = tail call i32 @err(i32 1, i32* null)
br label %13
13: ; preds = %4, %11, %7
%14 = phi i8* [ null, %11 ], [ %9, %7 ], [ %2, %4 ]
ret i8* %14
}