#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 /*<<< orphan*/ __builtin_stbio(unsigned char *, int);
void test_stbio(unsigned char *p1, unsigned char *p2) {
  __builtin_stbio(p1, *p2);
  __builtin_stbio(p2, 0);
  __builtin_stbio(p2 + 1, 0x80);
  __builtin_stbio(p2 + 2, 0x7f);
  __builtin_stbio(p2 + 2047, 0x80);
  __builtin_stbio(p2 + 2048, 0x7f);
}


x86 assembly (clang, -O0):
<test_stbio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
call   1030 <__builtin_stbio@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <__builtin_stbio@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x80,%esi
call   1030 <__builtin_stbio@plt>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    $0x7f,%esi
call   1030 <__builtin_stbio@plt>
mov    -0x10(%rbp),%rdi
add    $0x7ff,%rdi
mov    $0x80,%esi
call   1030 <__builtin_stbio@plt>
mov    -0x10(%rbp),%rdi
add    $0x800,%rdi
mov    $0x7f,%esi
call   1030 <__builtin_stbio@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_stbio>:
push   %rbx
mov    %rsi,%rbx
movzbl (%rsi),%esi
call   1030 <__builtin_stbio@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <__builtin_stbio@plt>
lea    0x1(%rbx),%rdi
mov    $0x80,%esi
call   1030 <__builtin_stbio@plt>
lea    0x2(%rbx),%rdi
mov    $0x7f,%esi
call   1030 <__builtin_stbio@plt>
lea    0x7ff(%rbx),%rdi
mov    $0x80,%esi
call   1030 <__builtin_stbio@plt>
add    $0x800,%rbx
mov    %rbx,%rdi
mov    $0x7f,%esi
pop    %rbx
jmp    1030 <__builtin_stbio@plt>

LLVM IR (-O0):
define void @test_stbio(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = call i32 @__builtin_stbio(i8* %5, i32 %8)
%10 = load i8*, i8** %4
%11 = call i32 @__builtin_stbio(i8* %10, i32 0)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = call i32 @__builtin_stbio(i8* %13, i32 128)
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = call i32 @__builtin_stbio(i8* %16, i32 127)
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 2047
%20 = call i32 @__builtin_stbio(i8* %19, i32 128)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 2048
%23 = call i32 @__builtin_stbio(i8* %22, i32 127)
ret void
}

LLVM IR (-O2):
define void @test_stbio(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = zext i8 %3 to i32
%5 = tail call i32 @__builtin_stbio(i8* %0, i32 %4)
%6 = tail call i32 @__builtin_stbio(i8* %1, i32 0)
%7 = getelementptr inbounds i8, i8* %1, i64 1
%8 = tail call i32 @__builtin_stbio(i8* %7, i32 128)
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = tail call i32 @__builtin_stbio(i8* %9, i32 127)
%11 = getelementptr inbounds i8, i8* %1, i64 2047
%12 = tail call i32 @__builtin_stbio(i8* %11, i32 128)
%13 = getelementptr inbounds i8, i8* %1, i64 2048
%14 = tail call i32 @__builtin_stbio(i8* %13, i32 127)
ret void
}