#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 /*<<< orphan*/ show_read_res(int, char);
void read_1_canon_mode(void) {
  char buf[32] = {0};
  int r;
  printf("read_1_canon_mode(): read 2 chars, one-by-one\n");
  r = read(0, buf, 1);
  show_read_res(r, buf[0]);
  r = read(0, buf, 1);
  show_read_res(r, buf[0]);
}


x86 assembly (clang, -O0):
<read_1_canon_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
movsbl -0x20(%rbp),%esi
call   1060 <show_read_res@plt>
lea    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
movsbl -0x20(%rbp),%esi
call   1060 <show_read_res@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_1_canon_mode>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
movsbl (%rsp),%esi
mov    %eax,%edi
call   1050 <show_read_res@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
movsbl (%rsp),%esi
mov    %eax,%edi
add    $0x20,%rsp
pop    %rbx
jmp    1050 <show_read_res@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"read_1_canon_mode(): read 2 chars, one-by-one\0A\00"
define void @read_1_canon_mode() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = bitcast [32 x i8]* %1 to i8*
%4 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %5, i32 1)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%9 = load i8, i8* %8
%10 = call i32 @show_read_res(i32 %7, i8 signext %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%12 = call i32 @read(i32 0, i8* %11, i32 1)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%15 = load i8, i8* %14
%16 = call i32 @show_read_res(i32 %13, i8 signext %15)
ret void
}

LLVM IR (-O2):
@str = [46 x i8] c"read_1_canon_mode(): read 2 chars, one-by-one\00"
define void @read_1_canon_mode() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%4 = call i32 @read(i32 0, i8* %2, i32 1)
%5 = load i8, i8* %2
%6 = tail call i32 @show_read_res(i32 %4, i8 signext %5)
%7 = call i32 @read(i32 0, i8* %2, i32 1)
%8 = load i8, i8* %2
%9 = tail call i32 @show_read_res(i32 %7, i8 signext %8)
ret void
}