#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;
};
typedef int /*<<< orphan*/ message;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_time(struct timespec);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ read_line(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, char *);
int /*<<< orphan*/ write(int, char *, size_t);
void active_pipe(int fd, char *buffer, size_t buffer_size, int i,
                 struct timespec start) {
  char *message = (char *)malloc(buffer_size);
  read_line(message, sizeof(message));
  char *timestamp = get_time(start);
  sprintf(buffer, "%s: Mensagem %.2d do usuário: <%s>", timestamp, i, message);
  write(fd, buffer, buffer_size);
  free(timestamp);
  free(message);
}


x86 assembly (clang, -O0):
<active_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1070 <read_line@plt>
mov    -0x8(%rbp),%edi
call   1050 <get_time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
lea    0xe49(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <write@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<active_pipe>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,0x4(%rsp)
mov    %rdx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x8,%esi
call   1070 <read_line@plt>
mov    %r12d,%edi
call   1050 <get_time@plt>
mov    %rax,%rbp
lea    0xe5b(%rip),%rsi
mov    %r13,%rdi
mov    %rax,%rdx
mov    %r15d,%ecx
mov    %rbx,%r8
call   1080 <sprintf@plt>
mov    0x4(%rsp),%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1040 <write@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [36 x i8] c"%s: Mensagem %.2d do usu\C3\A1rio: <%s>\00"
define void @active_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 = alloca i8*
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %4, i32* %13
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
%14 = load i64, i64* %9
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %11
%17 = load i8*, i8** %11
%18 = call i32 @read_line(i8* %17, i32 8)
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i8* @get_time(i32 %20)
store i8* %21, i8** %12
%22 = load i8*, i8** %8
%23 = load i8*, i8** %12
%24 = load i32, i32* %10
%25 = load i8*, i8** %11
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24, i8* %25)
%27 = load i32, i32* %7
%28 = load i8*, i8** %8
%29 = load i64, i64* %9
%30 = call i32 @write(i32 %27, i8* %28, i64 %29)
%31 = load i8*, i8** %12
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %11
%34 = call i32 @free(i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"%s: Mensagem %.2d do usu\C3\A1rio: <%s>\00"
define void @active_pipe(i32 %0, i8* nocapture %1, i64 %2, i32 %3, i32 %4) {
%6 = tail call i64 @malloc(i64 %2)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @read_line(i8* %7, i32 8)
%9 = tail call i8* @get_time(i32 %4)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %3, i8* %7)
%11 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i32 @free(i8* %7)
ret void
}