#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;
struct timeval {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ errno;
int fputs(char const *, int /*<<< orphan*/ *);
char *get_pidstr(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int mk_tvstamp(struct timeval *, char *, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int tmfputs(const char *s, FILE *stream) {
  int n = -1, rc = 0, NO_RESET = 0;
  char tstamp[80] = {'\0'};
  size_t ts_len = sizeof(tstamp) - 1;
  struct timeval tv_now;
  const char *pidstr = get_pidstr(NO_RESET);
  (void)gettimeofday(&tv_now, NULL);
  errno = 0;
  do {
    rc = mk_tvstamp(&tv_now, tstamp, &ts_len, 0);
    if (0 != rc)
      break;
    if ((n = fputs(tstamp, stream)) < 0 || (n = fputs("\t", stream)) < 0 ||
        (n = fputs(pidstr, stream)) < 0 || (n = fputs("\t", stream)) < 0)
      break;
    if ((n = fputs(s, stream)) < 0)
      break;
  } while (0);
  if (n < 0 && errno) {
    perror("fputs");
  }
  return (0 != rc) ? -1 : n;
}


x86 assembly (clang, -O0):
<tmfputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
movq   $0x4f,-0x78(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <get_pidstr@plt>
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    0x2e1d(%rip),%rax
movq   $0x0,(%rax)
lea    -0x70(%rbp),%rsi
lea    -0x80(%rbp),%rdi
lea    -0x78(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <mk_tvstamp@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
je     11f0 <tmfputs+0x90>
jmp    1285 <tmfputs+0x125>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     125d <tmfputs+0xfd>
mov    -0x10(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     125d <tmfputs+0xfd>
mov    -0x88(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     125d <tmfputs+0xfd>
mov    -0x10(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1262 <tmfputs+0x102>
jmp    1285 <tmfputs+0x125>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fputs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1280 <tmfputs+0x120>
jmp    1285 <tmfputs+0x125>
jmp    1285 <tmfputs+0x125>
cmpl   $0x0,-0x14(%rbp)
jge    12ac <tmfputs+0x14c>
mov    0x2d4a(%rip),%rax
cmpq   $0x0,(%rax)
je     12ac <tmfputs+0x14c>
lea    0xd5b(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
je     12c7 <tmfputs+0x167>
mov    $0xffffffff,%eax
mov    %eax,-0x8c(%rbp)
jmp    12d0 <tmfputs+0x170>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmfputs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x4f,0x8(%rsp)
xor    %edi,%edi
call   1050 <get_pidstr@plt>
mov    %rax,%r15
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2e3b(%rip),%r12
movq   $0x0,(%r12)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
xor    %ecx,%ecx
call   1060 <mk_tvstamp@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     11d0 <tmfputs+0x80>
test   %ebp,%ebp
js     1227 <tmfputs+0xd7>
jmp    122e <tmfputs+0xde>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
test   %eax,%eax
js     1221 <tmfputs+0xd1>
lea    0xe18(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
test   %eax,%eax
js     1221 <tmfputs+0xd1>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
test   %eax,%eax
js     1221 <tmfputs+0xd1>
lea    0xdf6(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
test   %eax,%eax
js     1221 <tmfputs+0xd1>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
mov    %eax,%ebp
test   %ebp,%ebp
jns    122e <tmfputs+0xde>
cmpq   $0x0,(%r12)
jne    123d <tmfputs+0xed>
mov    %ebp,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
jmp    122e <tmfputs+0xde>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@errno = global i64 0
@.str = [2 x i8] c"\09\00"
@.str.1 = [6 x i8] c"fputs\00"
define i32 @tmfputs(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [80 x i8]
%9 = alloca i64
%10 = alloca %struct.timeval
%11 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = bitcast [80 x i8]* %8 to i8*
store i64 79, i64* %9
%13 = load i32, i32* %7
%14 = call i8* @get_pidstr(i32 %13)
store i8* %14, i8** %11
%15 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
store i64 0, i64* @errno
br label %16
16: ; preds = %2
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%18 = call i32 @mk_tvstamp(%struct.timeval* %10, i8* %17, i64* %9, i32 0)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 0, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %48
22: ; preds = %16
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%24 = load i32*, i32** %4
%25 = call i32 @fputs(i8* %23, i32* %24)
store i32 %25, i32* %5
%26 = icmp slt i32 %25, 0
br i1 %26, label %40, label %27
27: ; preds = %22
%28 = load i32*, i32** %4
%29 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %28)
store i32 %29, i32* %5
%30 = icmp slt i32 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %27
%32 = load i8*, i8** %11
%33 = load i32*, i32** %4
%34 = call i32 @fputs(i8* %32, i32* %33)
store i32 %34, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %31
%37 = load i32*, i32** %4
%38 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %37)
store i32 %38, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36, %31, %27, %22
br label %48
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = load i32*, i32** %4
%44 = call i32 @fputs(i8* %42, i32* %43)
store i32 %44, i32* %5
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %48
47: ; preds = %41
br label %48
48: ; preds = %47, %46, %40, %21
%49 = load i32, i32* %5
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i64, i64* @errno
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %51, %48
%57 = load i32, i32* %6
%58 = icmp ne i32 0, %57
br i1 %58, label %59, label %60
59: ; preds = %56
br label %62
60: ; preds = %56
%61 = load i32, i32* %5
br label %62
62: ; preds = %60, %59
%63 = phi i32 [ -1, %59 ], [ %61, %60 ]
ret i32 %63
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@.str = [2 x i8] c"\09\00"
@.str.1 = [6 x i8] c"fputs\00"
define i32 @tmfputs(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = bitcast i64* %4 to i8*
store i64 79, i64* %4
%8 = bitcast %struct.timeval* %5 to i8*
%9 = tail call i8* @get_pidstr(i32 0)
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i64 0, i64* @errno
%11 = call i32 @mk_tvstamp(%struct.timeval* %5, i8* %6, i64* %4, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = call i32 @fputs(i8* %6, i32* %1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %1)
%18 = icmp slt i32 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %16
%20 = call i32 @fputs(i8* %9, i32* %1)
%21 = icmp slt i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %1)
%24 = icmp slt i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @fputs(i8* %0, i32* %1)
br label %27
27: ; preds = %25, %13, %16, %19, %22, %2
%28 = phi i32 [ %26, %25 ], [ %14, %13 ], [ %17, %16 ], [ %20, %19 ], [ %23, %22 ], [ -1, %2 ]
%29 = icmp slt i32 %28, 0
%30 = load i64, i64* @errno
%31 = icmp ne i64 %30, 0
%32 = select i1 %29, i1 %31, i1 false
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
ret i32 %28
}