#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 */
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, char *, size_t);
size_t syscall(int, int, long, int, int /*<<< orphan*/, int /*<<< orphan*/);
size_t read(int fd, void *buf, size_t count) {
  static char data[128] __attribute__((aligned(64)));
  int len = (((sizeof(data)) < (count)) ? (sizeof(data)) : (count));
  size_t cnt = syscall(63, fd, (long)data, len, 0, 0);
  memcpy(buf, data, cnt);
  return cnt;
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x80,%eax
cmp    -0x18(%rbp),%rax
jae    1150 <read+0x30>
mov    $0x80,%eax
mov    %rax,-0x30(%rbp)
jmp    1158 <read+0x38>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%ecx
mov    $0x3f,%edi
lea    0x2f0f(%rip),%rdx
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <syscall@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0x2ef1(%rip),%rsi
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%esi
cmp    $0x80,%rdx
mov    $0x80,%ecx
cmovb  %edx,%ecx
lea    0x2f40(%rip),%r14
mov    $0x3f,%edi
mov    %r14,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <syscall@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@read.data = internal global [128 x i8] zeroinitializer
define i64 @read(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = icmp ult i64 128, %9
br i1 %10, label %11, label %12
11: ; preds = %3
br label %14
12: ; preds = %3
%13 = load i64, i64* %6
br label %14
14: ; preds = %12, %11
%15 = phi i64 [ 128, %11 ], [ %13, %12 ]
%16 = trunc i64 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %4
%18 = load i32, i32* %7
%19 = call i64 @syscall(i32 63, i32 %17, i64 ptrtoint ([128 x i8]* @read.data to i64), i32 %18, i32 0, i32 0)
store i64 %19, i64* %8
%20 = load i8*, i8** %5
%21 = load i64, i64* %8
%22 = call i32 @memcpy(i8* %20, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @read.data, i64 0, i64 0), i64 %21)
%23 = load i64, i64* %8
ret i64 %23
}

LLVM IR (-O2):
@read.data = internal global [128 x i8] zeroinitializer
define i64 @read(i32 %0, i8* %1, i64 %2) {
%4 = icmp ult i64 %2, 128
%5 = select i1 %4, i64 %2, i64 128
%6 = trunc i64 %5 to i32
%7 = tail call i64 @syscall(i32 63, i32 %0, i64 ptrtoint ([128 x i8]* @read.data to i64), i32 %6, i32 0, i32 0)
%8 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @read.data, i64 0, i64 0), i64 %7)
ret i64 %7
}