#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*/ ssize_t;

/* Variables and functions */
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ stub1(int, void *, size_t);
ssize_t read(int fd, void *buf, size_t count) {
  static ssize_t (*func)(int, void *, size_t) = NULL;
  if (!func)
    func = (ssize_t(*)(int, void *, size_t))dlsym(((void *)-1L), "read");
  ;
  ssize_t r = (*func)(fd, buf, count);
  ;
  return r;
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,0x2f05(%rip)
jne    114b <read+0x3b>
mov    $0xffffffffffffffff,%rdi
lea    0xec1(%rip),%rsi
call   1030 <dlsym@plt>
mov    %rax,0x2ee5(%rip)
mov    0x2ede(%rip),%rax
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   *%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2f0d(%rip),%rax
test   %rax,%rax
jne    1142 <read+0x32>
lea    0xed1(%rip),%rsi
mov    $0xffffffffffffffff,%rdi
call   1030 <dlsym@plt>
mov    %rax,0x2eee(%rip)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    *%rax

LLVM IR (-O0):
@read.func = internal global i32 (i32, i8*, i64)* null
@.str = [5 x i8] c"read\00"
define i32 @read(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32 (i32, i8*, i64)*, i32 (i32, i8*, i64)** @read.func
%9 = icmp ne i32 (i32, i8*, i64)* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = inttoptr i64 %11 to i32 (i32, i8*, i64)*
store i32 (i32, i8*, i64)* %12, i32 (i32, i8*, i64)** @read.func
br label %13
13: ; preds = %10, %3
%14 = load i32 (i32, i8*, i64)*, i32 (i32, i8*, i64)** @read.func
%15 = load i32, i32* %4
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i32 %14(i32 %15, i8* %16, i64 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
ret i32 %19
}

LLVM IR (-O2):
@read.func = internal unnamed_addr global i32 (i32, i8*, i64)* null
@.str = [5 x i8] c"read\00"
define i32 @read(i32 %0, i8* %1, i64 %2) {
%4 = load i32 (i32, i8*, i64)*, i32 (i32, i8*, i64)** @read.func
%5 = icmp eq i32 (i32, i8*, i64)* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = inttoptr i64 %7 to i32 (i32, i8*, i64)*
store i32 (i32, i8*, i64)* %8, i32 (i32, i8*, i64)** @read.func
br label %9
9: ; preds = %6, %3
%10 = phi i32 (i32, i8*, i64)* [ %8, %6 ], [ %4, %3 ]
%11 = tail call i32 %10(i32 %0, i8* %1, i64 %2)
ret i32 %11
}