#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 */
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_time(struct timespec);
int /*<<< orphan*/ random_sleep_time();
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ write(int, char *, size_t);
void lazy_pipe(int fd, char *buffer, size_t buffer_size, int i,
               struct timespec start) {
  char *message = get_time(start);
  sprintf(buffer, "%s: Mensagem %.2d do filho dorminhoco", message, i);
  free(message);
  write(fd, buffer, buffer_size);
  sleep(random_sleep_time());
}


x86 assembly (clang, -O0):
<lazy_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8d,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <get_time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe68(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <write@plt>
mov    $0x0,%al
call   1060 <random_sleep_time@plt>
mov    %eax,%edi
call   1080 <sleep@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lazy_pipe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %r8d,%edi
call   1050 <get_time@plt>
mov    %rax,%rbp
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r12d,%ecx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <write@plt>
xor    %eax,%eax
call   1060 <random_sleep_time@plt>
mov    %eax,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sleep@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [38 x i8] c"%s: Mensagem %.2d do filho dorminhoco\00"
define void @lazy_pipe(i32 %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca %struct.timespec
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %4, i32* %12
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @get_time(i32 %14)
store i8* %15, i8** %11
%16 = load i8*, i8** %8
%17 = load i8*, i8** %11
%18 = load i32, i32* %10
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
%20 = load i8*, i8** %11
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %7
%23 = load i8*, i8** %8
%24 = load i64, i64* %9
%25 = call i32 @write(i32 %22, i8* %23, i64 %24)
%26 = call i32 (...) @random_sleep_time()
%27 = call i32 @sleep(i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"%s: Mensagem %.2d do filho dorminhoco\00"
define void @lazy_pipe(i32 %0, i8* nocapture %1, i64 %2, i32 %3, i32 %4) {
%6 = tail call i8* @get_time(i32 %4)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %3)
%8 = tail call i32 @free(i8* %6)
%9 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%10 = tail call i32 (...) @random_sleep_time()
%11 = tail call i32 @sleep(i32 %10)
ret void
}