#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 errno;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void err_doit(int useerrno, const char *fmt, va_list ap) {
  int errno_orig;
  char buf[1000 + 1];
  errno_orig = errno;
  vsnprintf(buf, 1000, fmt, ap);
  if (useerrno) {
    strncat(buf, ": ", 1000 + 1);
    strncat(buf, strerror(errno_orig), 1000 + 1);
  }
  strncat(buf, "\n", 1000 + 1);
  fputs(buf, stderr);
  return;
}


x86 assembly (clang, -O0):
<err_doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x3e8,%esi
call   1030 <vsnprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     11c5 <err_doit+0x85>
lea    -0x410(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x418(%rbp),%rdi
mov    %rax,%rsi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
lea    -0x410(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_doit>:
push   %rbp
push   %rbx
sub    $0x3f8,%rsp
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %edi,%ebp
mov    0x2e81(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1030 <vsnprintf@plt>
test   %ebp,%ebp
je     1198 <err_doit+0x58>
lea    0xe8f(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
mov    %ebx,%edi
call   1060 <strerror@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
lea    0xe64(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e9,%edx
call   1050 <strncat@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
add    $0x3f8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [3 x i8] c": \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
define void @err_doit(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1001 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @errno
store i32 %9, i32* %7
%10 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @vsnprintf(i8* %10, i32 1000, i8* %11, i32 %12)
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %3
%17 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%18 = call i32 @strncat(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 1001)
%19 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @strncat(i8* %19, i8* %21, i32 1001)
br label %23
23: ; preds = %16, %3
%24 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%25 = call i32 @strncat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1001)
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* @stderr
%28 = call i32 @fputs(i8* %26, i32 %27)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [3 x i8] c": \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
define void @err_doit(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1001 x i8]
%5 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @errno
%7 = call i32 @vsnprintf(i8* %5, i32 1000, i8* %1, i32 %2)
%8 = icmp eq i32 %0, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 1001)
%11 = call i8* @strerror(i32 %6)
%12 = call i32 @strncat(i8* %5, i8* %11, i32 1001)
br label %13
13: ; preds = %9, %3
%14 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1001)
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* %5, i32 %15)
ret void
}