#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*/ getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *);
void m_read(int fd) {
  int r_number;
  char buff[33];
  memset(buff, 0, 32);
  printf("input the number of bytes you want to read pls[1-32]:");
  scanf("%d", &r_number);
  getchar();
  if (r_number <= 0 || r_number > 32) {
    r_number = 4;
  }
  r_number = read(fd, buff, r_number);
  buff[r_number + 1] = '\0';
  printf("%s\n", buff);
}


x86 assembly (clang, -O0):
<m_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11a4 <m_read+0x54>
cmpl   $0x20,-0x8(%rbp)
jle    11ab <m_read+0x5b>
movl   $0x4,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_read>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0xc(%rsp),%edx
lea    -0x21(%rdx),%eax
cmp    $0xffffffdf,%eax
ja     11bb <m_read+0x5b>
movl   $0x4,0xc(%rsp)
mov    $0x4,%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <read@plt>
mov    %eax,0xc(%rsp)
cltq
movb   $0x0,0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"input the number of bytes you want to read pls[1-32]:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @m_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [33 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 32)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 (...) @getchar()
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 32
br i1 %14, label %15, label %16
15: ; preds = %12, %1
store i32 4, i32* %3
br label %16
16: ; preds = %15, %12
%17 = load i32, i32* %2
%18 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 @read(i32 %17, i8* %18, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"input the number of bytes you want to read pls[1-32]:\00"
@.str.1 = [3 x i8] c"%d\00"
define void @m_read(i32 %0) {
%2 = alloca i32
%3 = alloca [33 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 32)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 (...) @getchar()
%10 = load i32, i32* %2
%11 = add i32 %10, -33
%12 = icmp ult i32 %11, -32
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 4, i32* %2
br label %14
14: ; preds = %1, %13
%15 = phi i32 [ %10, %1 ], [ 4, %13 ]
%16 = call i32 @read(i32 %0, i8* %5, i32 %15)
store i32 %16, i32* %2
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @puts(i8* %5)
ret void
}