#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 */
int /*<<< orphan*/ STDIN_FILENO;
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ saferead(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  char buff[4];
  printf("main pid: %d, sizeof(ssize_t)=%lu, sizeof(int)=%lu\n", getpid(),
         sizeof(ssize_t), sizeof(int));
  saferead(STDIN_FILENO, buff, 4 - 1);
  buff[4 - 1] = '\0';
  printf("read: *%s*\n", buff);
  sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe9a(%rip),%rdi
mov    $0x4,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
mov    $0x3,%edx
call   1050 <saferead@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x14(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xead(%rip),%rdi
mov    $0x4,%edx
mov    $0x4,%ecx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x3,%edx
call   1050 <saferead@plt>
movb   $0x0,0xf(%rsp)
lea    0xea7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [52 x i8] c"main pid: %d, sizeof(ssize_t)=%lu, sizeof(int)=%lu\0A\00"
@STDIN_FILENO = global i32 0
@.str.1 = [12 x i8] c"read: *%s*\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @getpid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %7, i64 4, i64 4)
%9 = load i32, i32* @STDIN_FILENO
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%11 = call i32 @saferead(i32 %9, i8* %10, i32 3)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @sleep(i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"main pid: %d, sizeof(ssize_t)=%lu, sizeof(int)=%lu\0A\00"
@STDIN_FILENO = global i32 0
@.str.1 = [12 x i8] c"read: *%s*\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %5, i64 4, i64 4)
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @saferead(i32 %7, i8* %4, i32 3)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32 @sleep(i32 10)
ret i32 0
}