#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 stat {
  int st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
long MM_CONSOLE;
int MM_NOCON;
int MM_NOMSG;
int MM_NOTOK;
int MM_OK;
long MM_PRINT;
int S_IFDIR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *printfmt(char *, long, char const *, int, char const *, char const *,
               char const *);
int stat(char *, struct stat *);
int /*<<< orphan*/ *stderr;
char *strdup(char *);
scalar_t__ strlen(char *);
scalar_t__ validmsgverb(char *);
int fmtmsg(long class, const char *label, int sev, const char *text,
           const char *action, const char *tag) {
  FILE *fp;
  char *env, *msgverb, *output;
  int ret = MM_OK;
  if (action == NULL)
    action = "";
  if (class & MM_PRINT) {
    if ((env = getenv("MSGVERB")) != NULL && *env != '\0' &&
        strlen(env) <= strlen("label:severity:text:action:tag")) {
      if ((msgverb = strdup(env)) == NULL)
        return (MM_NOTOK);
      else if (validmsgverb(msgverb) == 0) {
        free(msgverb);
        goto def;
      }
    } else {
    def:
      if ((msgverb = strdup("label:severity:text:action:tag")) == NULL)
        return (MM_NOTOK);
    }
    output = printfmt(msgverb, class, label, sev, text, action, tag);
    if (output == NULL) {
      free(msgverb);
      return (MM_NOTOK);
    }
    if (*output != '\0') {
      int out_len = fprintf(stderr, "%s", output);
      if (out_len < 0) {
        ret = MM_NOMSG;
      }
    }
    free(msgverb);
    free(output);
  }
  if (class & MM_CONSOLE) {
    output = printfmt("label:severity:text:action:tag", class, label, sev, text,
                      action, tag);
    if (output == NULL)
      return (MM_NOCON);
    if (*output != '\0') {
      char *cpath = "/dev/console";
      struct stat sb;
      int rc = stat("/realdev/console", &sb);
      if (rc == 0 && (sb.st_mode & S_IFDIR)) {
        cpath = "/realdev/console";
      }
      if ((fp = fopen(cpath, "a")) == NULL) {
        if (ret == MM_OK) {
          ret = MM_NOCON;
        } else {
          ret = MM_NOTOK;
        }
      } else {
        fprintf(fp, "%s", output);
        fclose(fp);
      }
    }
    free(output);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<fmtmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e4 <fmtmsg+0x44>
lea    0xe27(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2df1(%rip),%rcx
and    (%rcx),%rax
cmp    $0x0,%rax
je     137e <fmtmsg+0x1de>
lea    0xdfd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     12a2 <fmtmsg+0x102>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a2 <fmtmsg+0x102>
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x80(%rbp)
lea    0xdce(%rip),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
cmp    %rcx,%rax
jg     12a2 <fmtmsg+0x102>
mov    -0x48(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1277 <fmtmsg+0xd7>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14b8 <fmtmsg+0x318>
mov    -0x50(%rbp),%rdi
call   10a0 <validmsgverb@plt>
cmp    $0x0,%rax
jne    1298 <fmtmsg+0xf8>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
jmp    12a7 <fmtmsg+0x107>
jmp    129d <fmtmsg+0xfd>
jmp    12d7 <fmtmsg+0x137>
jmp    12a7 <fmtmsg+0x107>
lea    0xd5a(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    12d2 <fmtmsg+0x132>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14b8 <fmtmsg+0x318>
jmp    12d7 <fmtmsg+0x137>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
mov    %rax,(%rsp)
call   1090 <printfmt@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1324 <fmtmsg+0x184>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14b8 <fmtmsg+0x318>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     136c <fmtmsg+0x1cc>
mov    0x2c85(%rip),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%rdx
lea    0xcde(%rip),%rsi
call   1070 <fprintf@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jge    1367 <fmtmsg+0x1c7>
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    136c <fmtmsg+0x1cc>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x2c47(%rip),%rcx
and    (%rcx),%rax
cmp    $0x0,%rax
je     14b2 <fmtmsg+0x312>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xc54(%rip),%rdi
mov    %rax,(%rsp)
call   1090 <printfmt@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    13dd <fmtmsg+0x23d>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14b8 <fmtmsg+0x318>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14a9 <fmtmsg+0x309>
lea    0xc36(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xc38(%rip),%rdi
lea    -0x70(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jne    1435 <fmtmsg+0x295>
mov    -0x70(%rbp),%eax
mov    0x2b89(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1435 <fmtmsg+0x295>
lea    0xc06(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xc08(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1487 <fmtmsg+0x2e7>
mov    -0x5c(%rbp),%eax
mov    0x2b43(%rip),%rcx
cmp    (%rcx),%eax
jne    1476 <fmtmsg+0x2d6>
mov    0x2b8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1482 <fmtmsg+0x2e2>
mov    0x2b3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    14a4 <fmtmsg+0x304>
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xb91(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
jmp    14a9 <fmtmsg+0x309>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmtmsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%r14
mov    0x2dd0(%rip),%r12
test   %r8,%r8
lea    0xe2d(%rip),%rbp
cmovne %r8,%rbp
mov    (%r12),%r13d
mov    0x2df7(%rip),%rax
test   %rdi,(%rax)
je     12f3 <fmtmsg+0x143>
mov    %r9,0x20(%rsp)
mov    %rdx,0x28(%rsp)
mov    %ecx,0x14(%rsp)
mov    %rbx,0x30(%rsp)
lea    0xdf4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1255 <fmtmsg+0xa5>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1255 <fmtmsg+0xa5>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x1e,%rax
jg     1255 <fmtmsg+0xa5>
mov    %rbx,%rdi
call   10d0 <strdup@plt>
test   %rax,%rax
je     1356 <fmtmsg+0x1a6>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <validmsgverb@plt>
test   %rax,%rax
jne    126d <fmtmsg+0xbd>
mov    %r15,%rdi
call   1040 <free@plt>
lea    0xdac(%rip),%rdi
call   10d0 <strdup@plt>
mov    %rax,%r15
test   %rax,%rax
je     1356 <fmtmsg+0x1a6>
mov    %r12,%rbx
mov    0x20(%rsp),%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    0x28(%rsp),%rdx
mov    0x14(%rsp),%ecx
mov    0x30(%rsp),%r8
mov    %rbp,%r9
call   10a0 <printfmt@plt>
test   %rax,%rax
je     134e <fmtmsg+0x19e>
mov    %rax,%r12
cmpb   $0x0,(%rax)
je     12cd <fmtmsg+0x11d>
mov    0x2d13(%rip),%rax
mov    (%rax),%rdi
lea    0xd70(%rip),%rsi
mov    %r12,%rdx
call   1080 <fprintf@plt>
test   %eax,%eax
jns    12cd <fmtmsg+0x11d>
mov    0x2d0e(%rip),%rax
mov    (%rax),%r13d
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %rbx,%r12
mov    0x30(%rsp),%rbx
mov    0x14(%rsp),%ecx
mov    0x28(%rsp),%rdx
mov    0x20(%rsp),%r9
mov    0x2cd6(%rip),%rax
test   %r14,(%rax)
je     13d3 <fmtmsg+0x223>
mov    %r9,(%rsp)
lea    0xcfa(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%r8
mov    %rbp,%r9
call   10a0 <printfmt@plt>
test   %rax,%rax
je     1362 <fmtmsg+0x1b2>
mov    %rax,%rbp
cmpb   $0x0,(%rax)
je     13cb <fmtmsg+0x21b>
lea    0xd03(%rip),%rbx
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <stat@plt>
test   %eax,%eax
je     136e <fmtmsg+0x1be>
lea    0xcde(%rip),%rbx
jmp    1386 <fmtmsg+0x1d6>
mov    %r15,%rdi
call   1040 <free@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%r13d
jmp    13d3 <fmtmsg+0x223>
mov    0x2c8f(%rip),%rax
mov    (%rax),%r13d
jmp    13d3 <fmtmsg+0x223>
mov    0x2c33(%rip),%rax
mov    (%rax),%eax
test   %eax,0x18(%rsp)
lea    0xca8(%rip),%rax
cmove  %rax,%rbx
lea    0xcbb(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13b2 <fmtmsg+0x202>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    13cb <fmtmsg+0x21b>
cmp    (%r12),%r13d
jne    13c1 <fmtmsg+0x211>
mov    0x2c39(%rip),%rax
jmp    13c8 <fmtmsg+0x218>
mov    0x2bf0(%rip),%rax
mov    (%rax),%r13d
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@MM_OK = global i32 0
@.str = [1 x i8] zeroinitializer
@MM_PRINT = global i64 0
@.str.1 = [8 x i8] c"MSGVERB\00"
@.str.2 = [31 x i8] c"label:severity:text:action:tag\00"
@MM_NOTOK = global i32 0
@stderr = global i32* null
@.str.3 = [3 x i8] c"%s\00"
@MM_NOMSG = global i32 0
@MM_CONSOLE = global i64 0
@MM_NOCON = global i32 0
@.str.4 = [13 x i8] c"/dev/console\00"
@.str.5 = [17 x i8] c"/realdev/console\00"
@S_IFDIR = global i32 0
@.str.6 = [2 x i8] c"a\00"
define i32 @fmtmsg(i64 %0, i8* %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca %struct.stat
%22 = alloca i32
store i64 %0, i64* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%23 = load i32, i32* @MM_OK
store i32 %23, i32* %18
%24 = load i8*, i8** %12
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %12
br label %27
27: ; preds = %26, %6
%28 = load i64, i64* %8
%29 = load i64, i64* @MM_PRINT
%30 = and i64 %28, %29
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %101
32: ; preds = %27
%33 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %15
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %60
35: ; preds = %32
%36 = load i8*, i8** %15
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %60
40: ; preds = %35
%41 = load i8*, i8** %15
%42 = call i64 @strlen(i8* %41)
%43 = call i64 @strlen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp sle i64 %42, %43
br i1 %44, label %45, label %60
45: ; preds = %40
%46 = load i8*, i8** %15
%47 = call i8* @strdup(i8* %46)
store i8* %47, i8** %16
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32, i32* @MM_NOTOK
store i32 %50, i32* %7
br label %159
51: ; preds = %45
%52 = load i8*, i8** %16
%53 = call i64 @validmsgverb(i8* %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i8*, i8** %16
%57 = call i32 @free(i8* %56)
br label %61
58: ; preds = %51
br label %59
59: ; preds = %58
br label %67
60: ; preds = %40, %35, %32
br label %61
61: ; preds = %60, %55
%62 = call i8* @strdup(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i8* %62, i8** %16
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = load i32, i32* @MM_NOTOK
store i32 %65, i32* %7
br label %159
66: ; preds = %61
br label %67
67: ; preds = %66, %59
%68 = load i8*, i8** %16
%69 = load i64, i64* %8
%70 = load i8*, i8** %9
%71 = load i32, i32* %10
%72 = load i8*, i8** %11
%73 = load i8*, i8** %12
%74 = load i8*, i8** %13
%75 = call i8* @printfmt(i8* %68, i64 %69, i8* %70, i32 %71, i8* %72, i8* %73, i8* %74)
store i8* %75, i8** %17
%76 = load i8*, i8** %17
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %82
78: ; preds = %67
%79 = load i8*, i8** %16
%80 = call i32 @free(i8* %79)
%81 = load i32, i32* @MM_NOTOK
store i32 %81, i32* %7
br label %159
82: ; preds = %67
%83 = load i8*, i8** %17
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %96
87: ; preds = %82
%88 = load i32*, i32** @stderr
%89 = load i8*, i8** %17
%90 = call i32 @fprintf(i32* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %89)
store i32 %90, i32* %19
%91 = load i32, i32* %19
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %87
%94 = load i32, i32* @MM_NOMSG
store i32 %94, i32* %18
br label %95
95: ; preds = %93, %87
br label %96
96: ; preds = %95, %82
%97 = load i8*, i8** %16
%98 = call i32 @free(i8* %97)
%99 = load i8*, i8** %17
%100 = call i32 @free(i8* %99)
br label %101
101: ; preds = %96, %27
%102 = load i64, i64* %8
%103 = load i64, i64* @MM_CONSOLE
%104 = and i64 %102, %103
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %157
106: ; preds = %101
%107 = load i64, i64* %8
%108 = load i8*, i8** %9
%109 = load i32, i32* %10
%110 = load i8*, i8** %11
%111 = load i8*, i8** %12
%112 = load i8*, i8** %13
%113 = call i8* @printfmt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %107, i8* %108, i32 %109, i8* %110, i8* %111, i8* %112)
store i8* %113, i8** %17
%114 = load i8*, i8** %17
%115 = icmp eq i8* %114, null
br i1 %115, label %116, label %118
116: ; preds = %106
%117 = load i32, i32* @MM_NOCON
store i32 %117, i32* %7
br label %159
118: ; preds = %106
%119 = load i8*, i8** %17
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %154
123: ; preds = %118
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8** %20
%124 = call i32 @stat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %21)
store i32 %124, i32* %22
%125 = load i32, i32* %22
%126 = icmp eq i32 %125, 0
br i1 %126, label %127, label %134
127: ; preds = %123
%128 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%129 = load i32, i32* %128
%130 = load i32, i32* @S_IFDIR
%131 = and i32 %129, %130
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %134
133: ; preds = %127
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %20
br label %134
134: ; preds = %133, %127, %123
%135 = load i8*, i8** %20
%136 = call i32* @fopen(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %136, i32** %14
%137 = icmp eq i32* %136, null
br i1 %137, label %138, label %147
138: ; preds = %134
%139 = load i32, i32* %18
%140 = load i32, i32* @MM_OK
%141 = icmp eq i32 %139, %140
br i1 %141, label %142, label %144
142: ; preds = %138
%143 = load i32, i32* @MM_NOCON
store i32 %143, i32* %18
br label %146
144: ; preds = %138
%145 = load i32, i32* @MM_NOTOK
store i32 %145, i32* %18
br label %146
146: ; preds = %144, %142
br label %153
147: ; preds = %134
%148 = load i32*, i32** %14
%149 = load i8*, i8** %17
%150 = call i32 @fprintf(i32* %148, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %149)
%151 = load i32*, i32** %14
%152 = call i32 @fclose(i32* %151)
br label %153
153: ; preds = %147, %146
br label %154
154: ; preds = %153, %118
%155 = load i8*, i8** %17
%156 = call i32 @free(i8* %155)
br label %157
157: ; preds = %154, %101
%158 = load i32, i32* %18
store i32 %158, i32* %7
br label %159
159: ; preds = %157, %116, %78, %64, %49
%160 = load i32, i32* %7
ret i32 %160
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@MM_OK = global i32 0
@.str = [1 x i8] zeroinitializer
@MM_PRINT = global i64 0
@.str.1 = [8 x i8] c"MSGVERB\00"
@.str.2 = [31 x i8] c"label:severity:text:action:tag\00"
@MM_NOTOK = global i32 0
@stderr = global i32* null
@.str.3 = [3 x i8] c"%s\00"
@MM_NOMSG = global i32 0
@MM_CONSOLE = global i64 0
@MM_NOCON = global i32 0
@.str.4 = [13 x i8] c"/dev/console\00"
@.str.5 = [17 x i8] c"/realdev/console\00"
@S_IFDIR = global i32 0
@.str.6 = [2 x i8] c"a\00"
define i32 @fmtmsg(i64 %0, i8* %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca %struct.stat
%8 = load i32, i32* @MM_OK
%9 = icmp eq i8* %4, null
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %4
%11 = load i64, i64* @MM_PRINT
%12 = and i64 %11, %0
%13 = icmp eq i64 %12, 0
br i1 %13, label %58, label %14
14: ; preds = %6
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %33, label %17
17: ; preds = %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = tail call i64 @strlen(i8* %15)
%22 = icmp slt i64 %21, 31
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = tail call i8* @strdup(i8* %15)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load i32, i32* @MM_NOTOK
br label %101
28: ; preds = %23
%29 = tail call i64 @validmsgverb(i8* %24)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = tail call i32 @free(i8* %24)
br label %33
33: ; preds = %14, %17, %20, %31
%34 = tail call dereferenceable_or_null(31) i8* @strdup(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i32, i32* @MM_NOTOK
br label %101
38: ; preds = %33, %28
%39 = phi i8* [ %34, %33 ], [ %24, %28 ]
%40 = tail call i8* @printfmt(i8* %39, i64 %0, i8* %1, i32 %2, i8* %3, i8* %10, i8* %5)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = tail call i32 @free(i8* %39)
%44 = load i32, i32* @MM_NOTOK
br label %101
45: ; preds = %38
%46 = load i8, i8* %40
%47 = icmp eq i8 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %45
%49 = load i32*, i32** @stderr
%50 = tail call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%51 = icmp slt i32 %50, 0
%52 = load i32, i32* @MM_NOMSG
%53 = select i1 %51, i32 %52, i32 %8
br label %54
54: ; preds = %48, %45
%55 = phi i32 [ %53, %48 ], [ %8, %45 ]
%56 = tail call i32 @free(i8* %39)
%57 = tail call i32 @free(i8* %40)
br label %58
58: ; preds = %54, %6
%59 = phi i32 [ %55, %54 ], [ %8, %6 ]
%60 = load i64, i64* @MM_CONSOLE
%61 = and i64 %60, %0
%62 = icmp eq i64 %61, 0
br i1 %62, label %101, label %63
63: ; preds = %58
%64 = tail call i8* @printfmt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %0, i8* %1, i32 %2, i8* %3, i8* %10, i8* %5)
%65 = icmp eq i8* %64, null
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = load i32, i32* @MM_NOCON
br label %101
68: ; preds = %63
%69 = load i8, i8* %64
%70 = icmp eq i8 %69, 0
br i1 %70, label %98, label %71
71: ; preds = %68
%72 = bitcast %struct.stat* %7 to i8*
%73 = call i32 @stat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %7)
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %82
75: ; preds = %71
%76 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%77 = load i32, i32* %76
%78 = load i32, i32* @S_IFDIR
%79 = and i32 %78, %77
%80 = icmp eq i32 %79, 0
%81 = select i1 %80, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0)
br label %82
82: ; preds = %75, %71
%83 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %71 ], [ %81, %75 ]
%84 = tail call i32* @fopen(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %93
86: ; preds = %82
%87 = load i32, i32* @MM_OK
%88 = icmp eq i32 %59, %87
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = load i32, i32* @MM_NOCON
br label %96
91: ; preds = %86
%92 = load i32, i32* @MM_NOTOK
br label %96
93: ; preds = %82
%94 = tail call i32 @fputs(i8* %64, i32* %84)
%95 = tail call i32 @fclose(i32* %84)
br label %96
96: ; preds = %89, %91, %93
%97 = phi i32 [ %90, %89 ], [ %92, %91 ], [ %59, %93 ]
br label %98
98: ; preds = %96, %68
%99 = phi i32 [ %97, %96 ], [ %59, %68 ]
%100 = tail call i32 @free(i8* %64)
br label %101
101: ; preds = %58, %98, %66, %42, %36, %26
%102 = phi i32 [ %27, %26 ], [ %37, %36 ], [ %44, %42 ], [ %67, %66 ], [ %99, %98 ], [ %59, %58 ]
ret i32 %102
}