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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
char *strerror(int);
int strlen(char *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void err_doit(const char *file, const char *function, int line, int errnoflag,
              int error, const char *fmt, va_list ap) {
  char buf[4096];
  snprintf(buf, 4096 - 1, "[File: %s][Function: %s][Line: %d] ", (char *)file,
           (char *)function, line);
  vsnprintf(buf + strlen(buf), 4096 - strlen(buf) - 1, fmt, ap);
  if (errnoflag)
    snprintf(buf + strlen(buf), 4096 - strlen(buf) - 1, ": %s\n",
             strerror(error));
  else
    snprintf(buf + strlen(buf), 4096 - strlen(buf) - 1, "\n");
  fflush(stdout);
  fputs(buf, stderr);
  fflush(NULL);
}


x86 assembly (clang, -O0):
<err_doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    $0xfff,%esi
lea    0xe5d(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1040(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1040(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1038(%rbp),%rdi
mov    $0x1000,%esi
sub    %eax,%esi
sub    $0x1,%esi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%ecx
call   1030 <vsnprintf@plt>
cmpl   $0x0,-0x18(%rbp)
je     1286 <err_doit+0x126>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1058(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1050(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x1000,%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x1044(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x1050(%rbp),%rdi
mov    -0x1044(%rbp),%esi
mov    %rax,%rcx
lea    0xdaa(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    12e1 <err_doit+0x181>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1068(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1068(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1060(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1060(%rbp),%rdi
mov    $0x1000,%esi
sub    %eax,%esi
sub    $0x1,%esi
lea    0xd4e(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%rdi
call   1070 <fflush@plt>
lea    -0x1030(%rbp),%rdi
mov    0x2ce2(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <fflush@plt>
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_doit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %r9,%r12
mov    %r8d,0xc(%rsp)
mov    %ecx,%r15d
mov    %edx,%r9d
mov    %rsi,%r8
mov    %rdi,%rcx
mov    0x1050(%rsp),%ebx
lea    0xe6d(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    $0xfff,%r14d
mov    %rbp,%rdi
mov    $0xfff,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%r13
add    $0x10,%r13
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0xfff,%esi
sub    %eax,%esi
mov    %r13,%rdi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1030 <vsnprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
sub    %eax,%r14d
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rbp
add    $0x10,%rbp
test   %r15d,%r15d
je     1222 <err_doit+0xc2>
mov    0xc(%rsp),%edi
call   1080 <strerror@plt>
lea    0xe14(%rip),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    1236 <err_doit+0xd6>
lea    0xdff(%rip),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%rdi
call   1070 <fflush@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1060 <fputs@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"[File: %s][Function: %s][Line: %d] \00"
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@stdout = global i32* null
@stderr = global i32 0
define void @err_doit(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca [4096 x i8]
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%17 = load i8*, i8** %8
%18 = load i8*, i8** %9
%19 = load i32, i32* %10
%20 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 4095, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i32 %19)
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 4096, %27
%29 = sub nsw i32 %28, 1
%30 = load i8*, i8** %13
%31 = load i32, i32* %14
%32 = call i32 @vsnprintf(i8* %25, i32 %29, i8* %30, i32 %31)
%33 = load i32, i32* %11
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %7
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sub nsw i32 4096, %42
%44 = sub nsw i32 %43, 1
%45 = load i32, i32* %12
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %40, i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %59
48: ; preds = %7
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 4096, %55
%57 = sub nsw i32 %56, 1
%58 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %53, i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %48, %35
%60 = load i32*, i32** @stdout
%61 = call i32 @fflush(i32* %60)
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%63 = load i32, i32* @stderr
%64 = call i32 @fputs(i8* %62, i32 %63)
%65 = call i32 @fflush(i32* null)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"[File: %s][Function: %s][Line: %d] \00"
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@stdout = global i32* null
@stderr = global i32 0
define void @err_doit(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i8* nocapture %5, i32 %6) {
%8 = alloca [4096 x i8]
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%10 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 4095, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2)
%11 = call i32 @strlen(i8* %9)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %12
%14 = call i32 @strlen(i8* %9)
%15 = sub i32 4095, %14
%16 = call i32 @vsnprintf(i8* %13, i32 %15, i8* %5, i32 %6)
%17 = icmp eq i32 %3, 0
%18 = call i32 @strlen(i8* %9)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %19
%21 = call i32 @strlen(i8* %9)
%22 = sub i32 4095, %21
br i1 %17, label %26, label %23
23: ; preds = %7
%24 = call i8* @strerror(i32 %4)
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %7
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i32*, i32** @stdout
%30 = call i32 @fflush(i32* %29)
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* %9, i32 %31)
%33 = call i32 @fflush(i32* null)
ret void
}