#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*/ tstamp_buf;
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct iovec {
  char *member_0;
  int /*<<< orphan*/ iov_len;
  int /*<<< orphan*/ member_1;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fmt_tstamp(char *, int, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write_all(struct iovec *, int);
void dump(FILE *f, char *del) {
  char buf[128];
  char tstamp_buf[32];
  struct iovec iov[] = {{tstamp_buf, 0}, {del, strlen(del)}, {buf, 0}};
  while (fgets(buf, sizeof(buf), f) != NULL) {
    struct timeval timeval;
    gettimeofday(&timeval, NULL);
    iov[0].iov_len = fmt_tstamp(tstamp_buf, sizeof(tstamp_buf), timeval.tv_sec,
                                timeval.tv_usec);
    iov[2].iov_len = strlen(buf);
    write_all(iov, 3);
  }
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
movl   $0x0,-0xd8(%rbp)
movl   $0x0,-0xd4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc8(%rbp)
movl   $0x0,-0xc4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movl   $0x0,-0xb8(%rbp)
movl   $0x0,-0xb4(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1245 <dump+0xf5>
lea    -0xe8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xe4(%rbp),%edx
mov    -0xe8(%rbp),%ecx
mov    $0x20,%esi
call   1070 <fmt_tstamp@plt>
mov    %eax,-0xd8(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xb8(%rbp)
lea    -0xe0(%rbp),%rdi
mov    $0x3,%esi
call   1060 <write_all@plt>
jmp    11cb <dump+0x7b>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe0,%rsp
mov    %rdi,%r12
lea    0x40(%rsp),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,0x28(%rsp)
movl   $0x0,0x2c(%rsp)
lea    0x60(%rsp),%rdi
mov    %rdi,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    $0x80,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1221 <dump+0xd1>
lea    0x8(%rsp),%r14
lea    0x40(%rsp),%r15
lea    0x60(%rsp),%rbx
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   1070 <fmt_tstamp@plt>
mov    %eax,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,0x38(%rsp)
mov    %r13,%rdi
mov    $0x3,%esi
call   1060 <write_all@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <dump+0x80>
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32, i32 }
%struct.timeval = type { i32, i32 }
define void @dump(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca [32 x i8]
%7 = alloca [3 x %struct.iovec]
%8 = alloca %struct.timeval
store i32* %0, i32** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
store i8* %11, i8** %10
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 1
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 2
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i64 1
%15 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
%16 = load i8*, i8** %4
store i8* %16, i8** %15
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 1
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %17
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 2
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i64 1
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 0
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8* %23, i8** %22
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 1
store i32 0, i32* %24
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 2
store i32 0, i32* %25
br label %26
26: ; preds = %31, %2
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%28 = load i32*, i32** %3
%29 = call i32* @fgets(i8* %27, i32 128, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %47
31: ; preds = %26
%32 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @fmt_tstamp(i8* %33, i32 32, i32 %35, i32 %37)
%39 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%40 = getelementptr inbounds %struct.iovec, %struct.iovec* %39, i32 0, i32 1
store i32 %38, i32* %40
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 2
%44 = getelementptr inbounds %struct.iovec, %struct.iovec* %43, i32 0, i32 1
store i32 %42, i32* %44
%45 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%46 = call i32 @write_all(%struct.iovec* %45, i32 3)
br label %26
47: ; preds = %26
ret void
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32, i32 }
%struct.timeval = type { i32, i32 }
define void @dump(i32* nocapture %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [32 x i8]
%5 = alloca [3 x %struct.iovec]
%6 = alloca %struct.timeval
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = bitcast [3 x %struct.iovec]* %5 to i8*
%10 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0
%11 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 0
store i8* %8, i8** %11
%12 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 1
store i32 0, i32* %12
%13 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 2
store i32 0, i32* %13
%14 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 0
store i8* %1, i8** %14
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 1
%16 = call i32 @strlen(i8* %1)
store i32 %16, i32* %15
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 2
store i32 0, i32* %17
%18 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 0
store i8* %7, i8** %18
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 1
store i32 0, i32* %19
%20 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 2
store i32 0, i32* %20
%21 = call i32* @fgets(i8* %7, i32 128, i32* %0)
%22 = icmp eq i32* %21, null
br i1 %22, label %36, label %23
23: ; preds = %2
%24 = bitcast %struct.timeval* %6 to i8*
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
br label %27
27: ; preds = %23, %27
%28 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%29 = load i32, i32* %25
%30 = load i32, i32* %26
%31 = call i32 @fmt_tstamp(i8* %8, i32 32, i32 %29, i32 %30)
store i32 %31, i32* %12
%32 = call i32 @strlen(i8* %7)
store i32 %32, i32* %19
%33 = call i32 @write_all(%struct.iovec* %10, i32 3)
%34 = call i32* @fgets(i8* %7, i32 128, i32* %0)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %27
36: ; preds = %27, %2
ret void
}