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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sleep(int);
void sleep_then_read(void) {
  char buf[32] = {0};
  int rc;
  printf("sleep\n");
  sleep(2);
  printf("sleep done, reading\n");
  rc = read(0, buf, sizeof(buf));
  printf("read(): %d -> '%s'\n", rc, buf);
}


x86 assembly (clang, -O0):
<sleep_then_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep_then_read>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
lea    0xe74(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"sleep\0A\00"
@.str.1 = [21 x i8] c"sleep done, reading\0A\00"
@.str.2 = [20 x i8] c"read(): %d -> '%s'\0A\00"
define void @sleep_then_read() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = bitcast [32 x i8]* %1 to i8*
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @sleep(i32 2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%8 = call i32 @read(i32 0, i8* %7, i32 32)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %10)
ret void
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"read(): %d -> '%s'\0A\00"
@str = [6 x i8] c"sleep\00"
@str.3 = [20 x i8] c"sleep done, reading\00"
define void @sleep_then_read() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @sleep(i32 2)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, i64 0, i64 0))
%6 = call i32 @read(i32 0, i8* %2, i32 32)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %6, i8* %2)
ret void
}