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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strfmon(char *, int, char *, double, double);
int main(void) {
  char buf[BUFSIZ];
  double val = 1234.567;
  setlocale(LC_ALL, "");
  strfmon(buf, sizeof buf, "You owe me %n (%i)\n", val, val);
  fputs(buf, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <setlocale@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe5c(%rip),%rdx
call   1050 <strfmon@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ea2(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1040 <setlocale@plt>
lea    0xe97(%rip),%rdx
movsd  0xe87(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14d,%esi
movaps %xmm0,%xmm1
call   1050 <strfmon@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [20 x i8] c"You owe me %n (%i)\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca double
store i32 0, i32* %1
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
store double 0x40934A449BA5E354, double* %4
%9 = load i32, i32* @LC_ALL
%10 = call i32 @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = trunc i64 %6 to i32
%12 = load double, double* %4
%13 = load double, double* %4
%14 = call i32 @strfmon(i8* %8, i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %12, double %13)
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* %8, i32 %15)
store i32 0, i32* %1
%17 = load i8*, i8** %2
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [20 x i8] c"You owe me %n (%i)\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @LC_ALL
%5 = tail call i32 @setlocale(i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strfmon(i8* %3, i32 %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double 0x40934A449BA5E354, double 0x40934A449BA5E354)
%7 = load i32, i32* @stdout
%8 = call i32 @fputs(i8* %3, i32 %7)
ret i32 0
}