#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*/ O_RDONLY;
size_t close(int);
int /*<<< orphan*/ fputlu(size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
size_t read(int, char *, int);
int /*<<< orphan*/ stdout;
void test3(int argc, char **argv) {
  int fd;
  char buff[64];
  size_t ret;
  puts("test3: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  fd = open("./main.c", O_RDONLY, 0644);
  fputs("test3: open: fd %d\n", stdout);
  ret = read(fd, buff, 64);
  fputs("test3: read: ret %zd\n", stdout);
  fputs("test3: read: buff '%.*s'\n", stdout);
  ret = close(fd);
  fputs("test3: close: ret %zd\n", stdout);
  fputs("test3: ret: ", stdout);
  fputlu(ret, stdout);
  puts("");
}


x86 assembly (clang, -O0):
<test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    %rax,-0x68(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    0xe76(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    %rax,-0x68(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x68(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
call   1030 <fputlu@plt>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe82(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,%ebx
mov    0x2e32(%rip),%r14
mov    (%r14),%esi
lea    0xe83(%rip),%rdi
call   1060 <fputs@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x40,%edx
call   1080 <read@plt>
mov    (%r14),%esi
lea    0xe79(%rip),%rdi
call   1060 <fputs@plt>
mov    (%r14),%esi
lea    0xe80(%rip),%rdi
call   1060 <fputs@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %rax,%rbx
mov    (%r14),%esi
lea    0xe81(%rip),%rdi
call   1060 <fputs@plt>
mov    (%r14),%esi
lea    0xe89(%rip),%rdi
call   1060 <fputs@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <fputlu@plt>
mov    $0xa,%edi
add    $0x48,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"test3: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\00"
@.str.1 = [9 x i8] c"./main.c\00"
@O_RDONLY = global i32 0
@.str.2 = [20 x i8] c"test3: open: fd %d\0A\00"
@stdout = global i32 0
@.str.3 = [22 x i8] c"test3: read: ret %zd\0A\00"
@.str.4 = [26 x i8] c"test3: read: buff '%.*s'\0A\00"
@.str.5 = [23 x i8] c"test3: close: ret %zd\0A\00"
@.str.6 = [13 x i8] c"test3: ret: \00"
@.str.7 = [1 x i8] zeroinitializer
define void @test3(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 420)
store i32 %10, i32* %5
%11 = load i32, i32* @stdout
%12 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %5
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 64)
store i64 %15, i64* %7
%16 = load i32, i32* @stdout
%17 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = call i64 @close(i32 %20)
store i64 %21, i64* %7
%22 = load i32, i32* @stdout
%23 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %24)
%26 = load i64, i64* %7
%27 = load i32, i32* @stdout
%28 = call i32 @fputlu(i64 %26, i32 %27)
%29 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"test3: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\00"
@.str.1 = [9 x i8] c"./main.c\00"
@O_RDONLY = global i32 0
@.str.2 = [20 x i8] c"test3: open: fd %d\0A\00"
@stdout = global i32 0
@.str.3 = [22 x i8] c"test3: read: ret %zd\0A\00"
@.str.4 = [26 x i8] c"test3: read: buff '%.*s'\0A\00"
@.str.5 = [23 x i8] c"test3: close: ret %zd\0A\00"
@.str.6 = [13 x i8] c"test3: ret: \00"
define void @test3(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 420)
%8 = load i32, i32* @stdout
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = call i64 @read(i32 %7, i8* %4, i32 64)
%11 = load i32, i32* @stdout
%12 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = tail call i64 @close(i32 %7)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stdout
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stdout
%21 = tail call i32 @fputlu(i64 %15, i32 %20)
%22 = tail call i32 @putchar(i32 10)
ret void
}