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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
char *libintl_vasnprintf(int /*<<< orphan*/ *, size_t *, char const *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ *strchr(char const *, char);
int vfprintf(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int libintl_vfprintf(FILE *stream, const char *format, va_list args) {
  if (strchr(format, '$') == NULL)
    return vfprintf(stream, format, args);
  else {
    size_t length;
    char *result = libintl_vasnprintf(NULL, &length, format, args);
    int retval = -1;
    if (result != NULL) {
      if (fwrite(result, 1, length, stream) == length)
        retval = length;
      free(result);
    }
    return retval;
  }
}


x86 assembly (clang, -O0):
<libintl_vfprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1193 <libintl_vfprintf+0x43>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <vfprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11f3 <libintl_vfprintf+0xa3>
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1050 <libintl_vasnprintf@plt>
mov    %rax,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ed <libintl_vfprintf+0x9d>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
cmp    -0x28(%rbp),%rax
jne    11e4 <libintl_vfprintf+0x94>
mov    -0x28(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libintl_vfprintf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ba <libintl_vfprintf+0x6a>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1050 <libintl_vasnprintf@plt>
test   %rax,%rax
je     11cf <libintl_vfprintf+0x7f>
mov    %rax,%rbp
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    0x8(%rsp),%rcx
cmp    %rcx,%rax
mov    $0xffffffff,%ebx
cmove  %ecx,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    11d4 <libintl_vfprintf+0x84>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <vfprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @libintl_vfprintf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = call i32* @strchr(i8* %11, i8 signext 36)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32*, i32** %5
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i32 @vfprintf(i32* %15, i8* %16, i32 %17)
store i32 %18, i32* %4
br label %40
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i8* @libintl_vasnprintf(i32* null, i64* %8, i8* %20, i32 %21)
store i8* %22, i8** %9
store i32 -1, i32* %10
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load i8*, i8** %9
%27 = load i64, i64* %8
%28 = load i32*, i32** %5
%29 = call i64 @fwrite(i8* %26, i32 1, i64 %27, i32* %28)
%30 = load i64, i64* %8
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i64, i64* %8
%34 = trunc i64 %33 to i32
store i32 %34, i32* %10
br label %35
35: ; preds = %32, %25
%36 = load i8*, i8** %9
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %35, %19
%39 = load i32, i32* %10
store i32 %39, i32* %4
br label %40
40: ; preds = %38, %14
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
define i32 @libintl_vfprintf(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = tail call i32* @strchr(i8* %1, i8 signext 36)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @vfprintf(i32* %0, i8* %1, i32 %2)
br label %23
9: ; preds = %3
%10 = bitcast i64* %4 to i8*
%11 = call i8* @libintl_vasnprintf(i32* null, i64* %4, i8* %1, i32 %2)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = load i64, i64* %4
%15 = call i64 @fwrite(i8* %11, i32 1, i64 %14, i32* %0)
%16 = load i64, i64* %4
%17 = icmp eq i64 %15, %16
%18 = trunc i64 %16 to i32
%19 = select i1 %17, i32 %18, i32 -1
%20 = call i32 @free(i8* %11)
br label %21
21: ; preds = %13, %9
%22 = phi i32 [ %19, %13 ], [ -1, %9 ]
br label %23
23: ; preds = %21, %7
%24 = phi i32 [ %8, %7 ], [ %22, %21 ]
ret i32 %24
}