#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 fread(char *, int, unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned char *);
int /*<<< orphan*/ stdin;
int main() {
  char buf[128];
  unsigned char size;
  printf("How much to read? ");
  scanf("%hhd\n", &size);
  if (size > 128)
    printf("Uh oh, reading up to %d bytes...\n", size);
  printf("Received: %d bytes.\n", fread(buf, 1, size, stdin));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x91(%rbp),%rsi
call   1050 <scanf@plt>
movzbl -0x91(%rbp),%eax
cmp    $0x80,%eax
jle    118a <main+0x5a>
movzbl -0x91(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x91(%rbp),%al
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x1,%esi
movzbl %al,%edx
call   1030 <fread@plt>
mov    %eax,%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x98,%rsp
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1050 <scanf@plt>
movzbl 0xf(%rsp),%esi
cmp    $0x81,%esi
jb     1176 <main+0x46>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xf(%rsp),%sil
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
movzbl %sil,%edx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"How much to read? \00"
@.str.1 = [6 x i8] c"%hhd\0A\00"
@.str.2 = [34 x i8] c"Uh oh, reading up to %d bytes...\0A\00"
@.str.3 = [21 x i8] c"Received: %d bytes.\0A\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp sgt i32 %7, 128
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i8, i8* %3
%11 = zext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9, %0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %3
%16 = load i32, i32* @stdin
%17 = call i32 @fread(i8* %14, i32 1, i8 zeroext %15, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [19 x i8] c"How much to read? \00"
@.str.1 = [6 x i8] c"%hhd\0A\00"
@.str.2 = [34 x i8] c"Uh oh, reading up to %d bytes...\0A\00"
@.str.3 = [21 x i8] c"Received: %d bytes.\0A\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = load i8, i8* %2
%7 = icmp ugt i8 %6, -128
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = zext i8 %6 to i32
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i8, i8* %2
br label %12
12: ; preds = %8, %0
%13 = phi i8 [ %11, %8 ], [ %6, %0 ]
%14 = load i32, i32* @stdin
%15 = call i32 @fread(i8* %3, i32 1, i8 zeroext %13, i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %15)
ret i32 0
}