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

/* Variables and functions */
int BUFSIZ;
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
void logStartStop(char *progName, int logfd, int start) {
  static char *savedProgName = (char *)0;
  static int savedLogfd = -1;
  time_t now;
  char buffer[BUFSIZ];
  char *tstring;
  if (progName && *progName)
    savedProgName = progName;
  if (logfd >= 0)
    savedLogfd = logfd;
  (void)time(&now);
  tstring = ctime(&now);
  tstring[strlen(tstring) - 1] = '\0';
  (void)snprintf(buffer, sizeof buffer, "%s: %s %s\n",
                 (savedProgName && *savedProgName) ? savedProgName : "logger",
                 start ? "starting" : "terminating", tstring);
  if (savedLogfd >= 0)
    (void)write(savedLogfd, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<logStartStop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b8 <logStartStop+0x68>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b8 <logStartStop+0x68>
mov    -0x8(%rbp),%rax
mov    %rax,0x2ea0(%rip)
cmpl   $0x0,-0xc(%rbp)
jl     11cb <logStartStop+0x7b>
mov    -0xc(%rbp),%eax
mov    %eax,0x2e7d(%rip)
lea    -0x14(%rbp),%rdi
call   1070 <time@plt>
lea    -0x14(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rcx
mov    %eax,%edx
mov    -0x40(%rbp),%rax
sub    $0x1,%edx
movslq %edx,%rdx
movb   $0x0,(%rcx,%rdx,1)
mov    %eax,-0x44(%rbp)
cmpq   $0x0,0x2e47(%rip)
je     123a <logStartStop+0xea>
mov    0x2e3a(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123a <logStartStop+0xea>
mov    0x2e27(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    124a <logStartStop+0xfa>
lea    0xdca(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    124a <logStartStop+0xfa>
mov    -0x44(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rcx
mov    -0x10(%rbp),%edx
lea    0xdbc(%rip),%r8
lea    0xdac(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r8
mov    -0x30(%rbp),%r9
lea    0xd88(%rip),%rdx
call   1060 <snprintf@plt>
cmpl   $0x0,0x2dc4(%rip)
jl     12aa <logStartStop+0x15a>
mov    -0x38(%rbp),%rdi
mov    0x2db4(%rip),%eax
mov    %eax,-0x5c(%rbp)
call   1050 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logStartStop>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsp,%r13
mov    0x2e75(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %rdi,%rdi
je     1190 <logStartStop+0x40>
cmpb   $0x0,(%rdi)
je     1190 <logStartStop+0x40>
mov    %rdi,0x2ec8(%rip)
test   %esi,%esi
js     119a <logStartStop+0x4a>
mov    %esi,0x2eae(%rip)
lea    -0x2c(%rbp),%rbx
mov    %rbx,%rdi
call   1070 <time@plt>
mov    %rbx,%rdi
call   1040 <ctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x2e91(%rip),%rax
test   %rax,%rax
je     11dc <logStartStop+0x8c>
cmpb   $0x0,(%rax)
lea    0xe35(%rip),%rcx
cmovne %rax,%rcx
jmp    11e3 <logStartStop+0x93>
lea    0xe28(%rip),%rcx
test   %r15d,%r15d
lea    0xe2e(%rip),%rax
lea    0xe1e(%rip),%r8
cmove  %rax,%r8
lea    0xe01(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rbx,%r9
call   1060 <snprintf@plt>
mov    0x2e35(%rip),%ebx
test   %ebx,%ebx
js     122b <logStartStop+0xdb>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@logStartStop.savedProgName = internal global i8* null
@logStartStop.savedLogfd = internal global i32 -1
@BUFSIZ = global i32 0
@.str = [11 x i8] c"%s: %s %s\0A\00"
@.str.1 = [7 x i8] c"logger\00"
@.str.2 = [9 x i8] c"starting\00"
@.str.3 = [12 x i8] c"terminating\00"
define void @logStartStop(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i8*, i8** %4
store i8* %23, i8** @logStartStop.savedProgName
br label %24
24: ; preds = %22, %17, %3
%25 = load i32, i32* %5
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* %5
store i32 %28, i32* @logStartStop.savedLogfd
br label %29
29: ; preds = %27, %24
%30 = call i32 @time(i32* %7)
%31 = call i8* @ctime(i32* %7)
store i8* %31, i8** %10
%32 = load i8*, i8** %10
%33 = load i8*, i8** %10
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 0, i8* %37
%38 = trunc i64 %12 to i32
%39 = load i8*, i8** @logStartStop.savedProgName
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %48
41: ; preds = %29
%42 = load i8*, i8** @logStartStop.savedProgName
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = load i8*, i8** @logStartStop.savedProgName
br label %49
48: ; preds = %41, %29
br label %49
49: ; preds = %48, %46
%50 = phi i8* [ %47, %46 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %48 ]
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0)
%55 = load i8*, i8** %10
%56 = call i32 @snprintf(i8* %14, i32 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %50, i8* %54, i8* %55)
%57 = load i32, i32* @logStartStop.savedLogfd
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %49
%60 = load i32, i32* @logStartStop.savedLogfd
%61 = call i32 @strlen(i8* %14)
%62 = call i32 @write(i32 %60, i8* %14, i32 %61)
br label %63
63: ; preds = %59, %49
%64 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@logStartStop.savedProgName = internal unnamed_addr global i8* null
@logStartStop.savedLogfd = internal unnamed_addr global i32 -1
@BUFSIZ = global i32 0
@.str = [11 x i8] c"%s: %s %s\0A\00"
@.str.1 = [7 x i8] c"logger\00"
@.str.2 = [9 x i8] c"starting\00"
@.str.3 = [12 x i8] c"terminating\00"
define void @logStartStop(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = icmp eq i8* %0, null
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11
store i8* %0, i8** @logStartStop.savedProgName
br label %15
15: ; preds = %14, %11, %3
%16 = icmp sgt i32 %1, -1
br i1 %16, label %17, label %18
17: ; preds = %15
store i32 %1, i32* @logStartStop.savedLogfd
br label %18
18: ; preds = %17, %15
%19 = call i32 @time(i32* %4)
%20 = call i8* @ctime(i32* %4)
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** @logStartStop.savedProgName
%26 = icmp eq i8* %25, null
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = load i8, i8* %25
%29 = icmp eq i8 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %25
br label %31
31: ; preds = %27, %18
%32 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %18 ], [ %30, %27 ]
%33 = icmp eq i32 %2, 0
%34 = select i1 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
%35 = call i32 @snprintf(i8* %9, i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %34, i8* %20)
%36 = load i32, i32* @logStartStop.savedLogfd
%37 = icmp sgt i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = call i32 @strlen(i8* %9)
%40 = call i32 @write(i32 %36, i8* %9, i32 %39)
br label %41
41: ; preds = %38, %31
ret void
}