#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcat(char *, char *);
char *strerror(int);
int strlen(char *);
int /*<<< orphan*/ vsprintf(char *, char const *, int /*<<< orphan*/);
void SR_ErrDoit(int errnoflag, const char *fmt, va_list ap) {
  int errno_save;
  char buf[4096];
  errno_save = errno;
  vsprintf(buf, fmt, ap);
  if (errnoflag)
    sprintf(buf + strlen(buf), ": %s", strerror(errno_save));
  strcat(buf, "\n");
  fflush(stdout);
  fputs(buf, stderr);
  fflush(NULL);
  return;
}


x86 assembly (clang, -O0):
<SR_ErrDoit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <vsprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     11fc <SR_ErrDoit+0x8c>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1030(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1028(%rbp)
mov    -0x18(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x1028(%rbp),%rdi
mov    %rax,%rdx
lea    0xe09(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <strcat@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%rdi
call   1050 <fflush@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SR_ErrDoit>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %edi,%ebp
mov    0x2e56(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%rdi
call   1060 <vsprintf@plt>
test   %ebp,%ebp
je     11b7 <SR_ErrDoit+0x47>
mov    %rsp,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe54(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
call   1080 <sprintf@plt>
lea    0xe47(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%rdi
call   1050 <fflush@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.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 @SR_ErrDoit(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 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 [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @vsprintf(i8* %10, i8* %11, i32 %12)
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %3
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, 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 = load i32, i32* %7
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %16, %3
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32*, i32** @stdout
%29 = call i32 @fflush(i32* %28)
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* %30, i32 %31)
%33 = call i32 @fflush(i32* null)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.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 @SR_ErrDoit(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @errno
%7 = call i32 @vsprintf(i8* %5, i8* %1, i32 %2)
%8 = icmp eq i32 %0, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = call i32 @strlen(i8* %5)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %11
%13 = call i8* @strerror(i32 %6)
%14 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %9, %3
%16 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32*, i32** @stdout
%18 = call i32 @fflush(i32* %17)
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* %5, i32 %19)
%21 = call i32 @fflush(i32* null)
ret void
}