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

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strerror(int);
char *ec_os_err_string(int err, int grp, char *buf, int size) {
  if (err == 0)
    return "";
  else {
    char *message = strerror(err);
    if (message)
      return message;
    sprintf(buf, "Unix error %d", err);
    return buf;
  }
}


x86 assembly (clang, -O0):
<ec_os_err_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114f <ec_os_err_string+0x2f>
lea    0xec7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <ec_os_err_string+0x6e>
mov    -0xc(%rbp),%edi
call   1040 <strerror@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1173 <ec_os_err_string+0x53>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <ec_os_err_string+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe7f(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_os_err_string>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
je     114c <ec_os_err_string+0x2c>
mov    %rdx,%rbx
mov    %edi,%ebp
call   1040 <strerror@plt>
test   %rax,%rax
jne    1153 <ec_os_err_string+0x33>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <sprintf@plt>
mov    %rbx,%rax
jmp    1153 <ec_os_err_string+0x33>
lea    0xeba(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [14 x i8] c"Unix error %d\00"
define i8* @ec_os_err_string(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
br label %26
14: ; preds = %4
%15 = load i32, i32* %6
%16 = call i8* @strerror(i32 %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i8*, i8** %10
store i8* %20, i8** %5
br label %26
21: ; preds = %14
%22 = load i8*, i8** %8
%23 = load i32, i32* %6
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** %8
store i8* %25, i8** %5
br label %26
26: ; preds = %21, %19, %13
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [14 x i8] c"Unix error %d\00"
define i8* @ec_os_err_string(i32 %0, i32 %1, i8* writeonly %2, i32 %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = tail call i8* @strerror(i32 %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %11
11: ; preds = %9, %6, %4
%12 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %4 ], [ %2, %9 ], [ %7, %6 ]
ret i8* %12
}