#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*/ va_list;
typedef int /*<<< orphan*/ fmtbuf;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ expand_error(char const *, char *, int, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strrchr(char const *, char);
char *strstr(char const *, char *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char const *,
                            int /*<<< orphan*/);
void warnv(const char *fmt, va_list ap) {
  static char fmtbuf[128];
  int saved_errno;
  const char *nl;
  const char *m;
  saved_errno = errno;
  assert(fmt != NULL);
  m = strstr(fmt, "%m");
  if (m != NULL) {
    expand_error(fmt, fmtbuf, sizeof(fmtbuf), saved_errno);
    fmt = fmtbuf;
  }
  vfprintf(stderr, fmt, ap);
  nl = strrchr(fmt, '\n');
  if (nl == NULL || nl[1] != '\0')
    fputc('\n', stderr);
}


x86 assembly (clang, -O0):
<warnv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cf <warnv+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%ecx
lea    0x2ea6(%rip),%rsi
mov    $0x80,%edx
call   1060 <expand_error@plt>
lea    0x2e95(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <vfprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1212 <warnv+0xb2>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1225 <warnv+0xc5>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warnv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e64(%rip),%rax
mov    (%rax),%ebp
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11b4 <warnv+0x54>
lea    0x2ec1(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x80,%edx
mov    %ebp,%ecx
call   1060 <expand_error@plt>
mov    %r15,%rbx
mov    0x2e25(%rip),%rbp
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <vfprintf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     11e1 <warnv+0x81>
cmpb   $0x0,0x1(%rax)
je     11f8 <warnv+0x98>
mov    0x0(%rbp),%esi
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@warnv.fmtbuf = internal global [128 x i8] zeroinitializer
@errno = global i32 0
@.str = [3 x i8] c"%m\00"
@stderr = global i32 0
define void @warnv(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* @errno
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %3
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = call i32 @expand_error(i8* %18, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @warnv.fmtbuf, i64 0, i64 0), i32 128, i32 %19)
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @warnv.fmtbuf, i64 0, i64 0), i8** %3
br label %21
21: ; preds = %17, %2
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = call i32 @vfprintf(i32 %22, i8* %23, i32 %24)
%26 = load i8*, i8** %3
%27 = call i8* @strrchr(i8* %26, i8 signext 10)
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = icmp eq i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30, %21
%37 = load i32, i32* @stderr
%38 = call i32 @fputc(i8 signext 10, i32 %37)
br label %39
39: ; preds = %36, %30
ret void
}

LLVM IR (-O2):
@warnv.fmtbuf = internal global [128 x i8] zeroinitializer
@errno = global i32 0
@.str = [3 x i8] c"%m\00"
@stderr = global i32 0
define void @warnv(i8* %0, i32 %1) {
%3 = load i32, i32* @errno
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @expand_error(i8* %0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @warnv.fmtbuf, i64 0, i64 0), i32 128, i32 %3)
br label %11
11: ; preds = %9, %2
%12 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @warnv.fmtbuf, i64 0, i64 0), %9 ], [ %0, %2 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 @vfprintf(i32 %13, i8* %12, i32 %1)
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %12, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17, %11
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputc(i8 signext 10, i32 %22)
br label %24
24: ; preds = %21, %17
ret void
}