#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 errno;
int httpGetError();
int /*<<< orphan*/ httpResetError();
scalar_t__ malloc(int);
int snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, int, int,
             char const *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, char const *);
char *strerror(int);
char *httpGetErrorText() {
  const char *perr;
  int err = httpGetError(), retLen;
  char *ret;
  httpResetError();
  if (err == 0)
    return "0; No Error.";
  perr = strerror(errno);
  retLen =
      snprintf(NULL, 0, "%i; Socket error: (%i) \"%s\"", err, errno, perr) + 1;
  ret = (char *)malloc(retLen);
  sprintf(ret, "%i; Socket error: (%i) \"%s\"", err, errno, perr);
  errno = 0;
  return ret;
}


x86 assembly (clang, -O0):
<httpGetErrorText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <httpGetError@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <httpResetError@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1193 <httpGetErrorText+0x33>
lea    0xe76(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    120f <httpGetErrorText+0xaf>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
mov    0x2e31(%rip),%rax
mov    (%rax),%r8d
mov    -0x10(%rbp),%r9
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe4a(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    0x2df8(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8
lea    0xe18(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2ddf(%rip),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpGetErrorText>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1060 <httpGetError@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <httpResetError@plt>
test   %ebp,%ebp
je     11d4 <httpGetErrorText+0x74>
mov    0x2e5d(%rip),%r12
mov    (%r12),%edi
call   1080 <strerror@plt>
mov    %rax,%r14
mov    (%r12),%r8d
lea    0xe73(%rip),%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    %rax,%r9
call   1030 <snprintf@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    (%r12),%ecx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14,%r8
call   1070 <sprintf@plt>
movl   $0x0,(%r12)
jmp    11db <httpGetErrorText+0x7b>
lea    0xe25(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"0; No Error.\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"%i; Socket error: (%i) \22%s\22\00"
define i8* @httpGetErrorText() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = call i32 (...) @httpGetError()
store i32 %6, i32* %3
%7 = call i32 (...) @httpResetError()
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %1
br label %28
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
store i8* %13, i8** %2
%14 = load i32, i32* %3
%15 = load i32, i32* @errno
%16 = load i8*, i8** %2
%17 = call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i8* %16)
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i32, i32* %3
%24 = load i32, i32* @errno
%25 = load i8*, i8** %2
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24, i8* %25)
store i32 0, i32* @errno
%27 = load i8*, i8** %5
store i8* %27, i8** %1
br label %28
28: ; preds = %11, %10
%29 = load i8*, i8** %1
ret i8* %29
}

LLVM IR (-O2):
@.str = [13 x i8] c"0; No Error.\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"%i; Socket error: (%i) \22%s\22\00"
define i8* @httpGetErrorText() {
%1 = tail call i32 (...) @httpGetError()
%2 = tail call i32 (...) @httpResetError()
%3 = icmp eq i32 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i8* @strerror(i32 %5)
%7 = load i32, i32* @errno
%8 = tail call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %7, i8* %6)
%9 = add nsw i32 %8, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = load i32, i32* @errno
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %12, i8* %6)
store i32 0, i32* @errno
br label %14
14: ; preds = %0, %4
%15 = phi i8* [ %11, %4 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %0 ]
ret i8* %15
}