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

/* Variables and functions */
int /*<<< orphan*/ hug_create_header(char *, int);
int strlen(char const *);
int write(int, char const *, int);
int hug_output_fd(int fd, const char *msg, int withdate) {
  int s;
  if (fd == -1)
    return 1;
  if (withdate) {
    char hdr[32];
    hug_create_header(hdr, sizeof(hdr));
    s = write(fd, hdr, strlen(hdr));
    s = write(fd, " ", 1);
  }
  s = write(fd, msg, strlen(msg));
  if (msg[strlen(msg) - 1] != '\n') {
    s = write(fd, "\n", 1);
  }
  (void)s;
  return 0;
}


x86 assembly (clang, -O0):
<hug_output_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1158 <hug_output_fd+0x28>
movl   $0x1,-0x4(%rbp)
jmp    121f <hug_output_fd+0xef>
cmpl   $0x0,-0x14(%rbp)
je     11af <hug_output_fd+0x7f>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1050 <hug_create_header@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe5e(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1218 <hug_output_fd+0xe8>
mov    -0x8(%rbp),%edi
lea    0xdf7(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hug_output_fd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0xffffffff,%edi
je     11ba <hug_output_fd+0x8a>
mov    %rsi,%rbx
mov    %edi,%ebp
test   %edx,%edx
je     117d <hug_output_fd+0x4d>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <hug_create_header@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe8f(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %r14d,%r14d
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11c0 <hug_output_fd+0x90>
lea    0xe56(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11c0 <hug_output_fd+0x90>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @hug_output_fd(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 1, i32* %4
br label %46
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%18 = call i32 @hug_create_header(i8* %17, i32 32)
%19 = load i32, i32* %5
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @write(i32 %19, i8* %20, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %5
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %25, i32* %8
br label %26
26: ; preds = %16, %13
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @write(i32 %27, i8* %28, i32 %30)
store i32 %31, i32* %8
%32 = load i8*, i8** %6
%33 = load i8*, i8** %6
%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
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %44
41: ; preds = %26
%42 = load i32, i32* %5
%43 = call i32 @write(i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 %43, i32* %8
br label %44
44: ; preds = %41, %26
%45 = load i32, i32* %8
store i32 0, i32* %4
br label %46
46: ; preds = %44, %12
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @hug_output_fd(i32 %0, i8* %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = icmp eq i32 %0, -1
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = call i32 @hug_create_header(i8* %9, i32 32)
%11 = call i32 @strlen(i8* %9)
%12 = call i32 @write(i32 %0, i8* %9, i32 %11)
%13 = call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %14
14: ; preds = %8, %6
%15 = call i32 @strlen(i8* %1)
%16 = call i32 @write(i32 %0, i8* %1, i32 %15)
%17 = call i32 @strlen(i8* %1)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %25, label %23
23: ; preds = %14
%24 = call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %25
25: ; preds = %14, %23, %3
%26 = phi i32 [ 1, %3 ], [ 0, %23 ], [ 0, %14 ]
ret i32 %26
}