#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*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int write(int /*<<< orphan*/, char *, int);
void write_to_stdin(void) {
  char c = 'a';
  int r;
  printf("Write 'a' to stdin\n");
  r = write(0, &c, 1);
  printf("write() -> %d\n", r);
  printf("now read 1 byte from stdin\n");
  r = read(0, &c, 1);
  printf("read(%d): 0x%x\n", r, c);
}


x86 assembly (clang, -O0):
<write_to_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x61,-0x1(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
movsbl -0x1(%rbp),%edx
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_stdin>:
push   %rbx
sub    $0x10,%rsp
movb   $0x61,0xf(%rsp)
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0xf(%rsp),%edx
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Write 'a' to stdin\0A\00"
@.str.1 = [15 x i8] c"write() -> %d\0A\00"
@.str.2 = [28 x i8] c"now read 1 byte from stdin\0A\00"
@.str.3 = [16 x i8] c"read(%d): 0x%x\0A\00"
define void @write_to_stdin() {
%1 = alloca i8
%2 = alloca i32
store i8 97, i8* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @write(i32 0, i8* %1, i32 1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @read(i32 0, i8* %1, i32 1)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %11)
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"write() -> %d\0A\00"
@.str.3 = [16 x i8] c"read(%d): 0x%x\0A\00"
@str = [19 x i8] c"Write 'a' to stdin\00"
@str.4 = [27 x i8] c"now read 1 byte from stdin\00"
define void @write_to_stdin() {
%1 = alloca i8
store i8 97, i8* %1
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%3 = call i32 @write(i32 0, i8* %1, i32 1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0))
%6 = call i32 @read(i32 0, i8* %1, i32 1)
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %8)
ret void
}