#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 */
char *alloca(size_t);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ byte_diff(char *, int, char *);
size_t fmt_strm_internal(char *, char *, char *, char *, char *);
int main() {
  char *c = ({
    size_t len =
        fmt_strm_internal((char *)0, "foo", " bar", "\n", (char *)0) + 1;
    char *c = (len < 100000 ? alloca(len) : 0);
    if (c)
      c[fmt_strm_internal(c, "foo", " bar", "\n", (char *)0)] = 0;
    c;
  });
  assert((!byte_diff((c), (sizeof("foo bar\n")), ("foo bar\n"))));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%r8d
lea    0xea5(%rip),%rsi
lea    0xea2(%rip),%rdx
lea    0xea7(%rip),%rcx
mov    %r8,%rdi
call   1030 <fmt_strm_internal@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x186a0,-0x18(%rbp)
jae    1199 <main+0x59>
mov    -0x18(%rbp),%rdi
call   1060 <alloca@plt>
mov    %rax,-0x30(%rbp)
jmp    11a4 <main+0x64>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11a4 <main+0x64>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ed <main+0xad>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe36(%rip),%rsi
lea    0xe33(%rip),%rdx
lea    0xe38(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <fmt_strm_internal@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xdfc(%rip),%rdx
call   1040 <byte_diff@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rsi
lea    0xeb5(%rip),%rdx
lea    0xeba(%rip),%rcx
xor    %ebx,%ebx
xor    %edi,%edi
xor    %r8d,%r8d
call   1030 <fmt_strm_internal@plt>
add    $0x1,%rax
cmp    $0x1869f,%rax
ja     11a6 <main+0x66>
mov    %rax,%rdi
call   1060 <alloca@plt>
test   %rax,%rax
je     11a4 <main+0x64>
mov    %rax,%rbx
lea    0xe7b(%rip),%rsi
lea    0xe78(%rip),%rdx
lea    0xe7d(%rip),%rcx
mov    %rax,%rdi
xor    %r8d,%r8d
call   1030 <fmt_strm_internal@plt>
movb   $0x0,(%rbx,%rax,1)
jmp    11a6 <main+0x66>
xor    %ebx,%ebx
lea    0xe5c(%rip),%rdx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <byte_diff@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@.str.1 = [5 x i8] c" bar\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [9 x i8] c"foo bar\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i64 @fmt_strm_internal(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* null)
%7 = add i64 %6, 1
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp ult i64 %8, 100000
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i64, i64* %3
%12 = call i8* @alloca(i64 %11)
br label %14
13: ; preds = %0
br label %14
14: ; preds = %13, %10
%15 = phi i8* [ %12, %10 ], [ null, %13 ]
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8*, i8** %4
%21 = call i64 @fmt_strm_internal(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* null)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %18, %14
%24 = load i8*, i8** %4
store i8* %24, i8** %5
%25 = load i8*, i8** %5
store i8* %25, i8** %2
%26 = load i8*, i8** %2
%27 = call i32 @byte_diff(i8* %26, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@.str.1 = [5 x i8] c" bar\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [9 x i8] c"foo bar\0A\00"
define i32 @main() {
%1 = tail call i64 @fmt_strm_internal(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* null)
%2 = add i64 %1, 1
%3 = icmp ult i64 %2, 100000
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = tail call i8* @alloca(i64 %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @fmt_strm_internal(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* null)
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 0, i8* %9
br label %10
10: ; preds = %0, %7, %4
%11 = phi i8* [ %5, %7 ], [ null, %4 ], [ null, %0 ]
%12 = tail call i32 @byte_diff(i8* %11, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i32 0
}