#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*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcat(char *, char *);
char *strerror(int);
int strlen(char *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void err_doit(int errnoflag, int error, const char *fmt, va_list ap) {
  char buf[4096];
  vsnprintf(buf, 4096, fmt, ap);
  if (errnoflag)
    snprintf(buf + strlen(buf), 4096 - strlen(buf), ":%s", strerror(error));
  strcat(buf, " ");
  fflush(stdout);
  fputs(buf, stderr);
  fflush(NULL);
  printf("\n");
}


x86 assembly (clang, -O0):
<err_doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x1000,%esi
call   1030 <vsnprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1229 <err_doit+0xa9>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1038(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x1000,%eax
sub    %ecx,%eax
mov    %eax,-0x1024(%rbp)
mov    -0x8(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x1030(%rbp),%rdi
mov    -0x1024(%rbp),%esi
mov    %rax,%rcx
lea    0xddc(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1090 <strcat@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%rdi
call   1080 <fflush@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
lea    0xd96(%rip),%rdi
call   1050 <printf@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_doit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x1000,%ebx
mov    $0x1000,%esi
call   1040 <vsnprintf@plt>
test   %ebp,%ebp
je     11df <err_doit+0x5f>
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %eax,%ebx
mov    %r14d,%edi
call   10a0 <strerror@plt>
lea    0xe2e(%rip),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
lea    0xe1e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%rdi
call   1080 <fflush@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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