#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 *, 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[80];
  vsnprintf(buf, 80, fmt, ap);
  if (errnoflag)
    snprintf(buf + strlen(buf), 80 - strlen(buf), ": %s", strerror(error));
  strcat(buf, "\n");
  fflush(stdout);
  fputs(buf, stderr);
  fflush(NULL);
}


x86 assembly (clang, -O0):
<err_doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x50,%esi
call   1030 <vsnprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1201 <err_doit+0x91>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x50,%eax
sub    %ecx,%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x80(%rbp),%rdi
mov    -0x74(%rbp),%esi
mov    %rax,%rcx
lea    0xe04(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1080 <strcat@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rdi
call   1070 <fflush@plt>
lea    -0x70(%rbp),%rdi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <fflush@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_doit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x50,%ebx
mov    $0x50,%esi
call   1030 <vsnprintf@plt>
test   %ebp,%ebp
je     11cc <err_doit+0x5c>
mov    %rsp,%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
mov    %r14d,%edi
call   1090 <strerror@plt>
lea    0xe41(%rip),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe32(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rdi
call   1070 <fflush@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <fputs@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c": %s\00"
@.str.1 = [2 x i8] c"\0A\00"
@stdout = global i32* null
@stderr = global i32 0
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 [80 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 [80 x i8], [80 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = call i32 @vsnprintf(i8* %10, i32 80, 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 [80 x i8], [80 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [80 x i8], [80 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 [80 x i8], [80 x i8]* %9, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 80, %23
%25 = load i32, i32* %6
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @snprintf(i8* %21, i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %16, %4
%29 = getelementptr inbounds [80 x i8], [80 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 [80 x i8], [80 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)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c": %s\00"
@.str.1 = [2 x i8] c"\0A\00"
@stdout = global i32* null
@stderr = global i32 0
define void @err_doit(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%7 = call i32 @vsnprintf(i8* %6, i32 80, 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 [80 x i8], [80 x i8]* %5, i64 0, i64 %11
%13 = call i32 @strlen(i8* %6)
%14 = sub nsw i32 80, %13
%15 = call i8* @strerror(i32 %1)
%16 = call i32 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([5 x i8], [5 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)
ret void
}