#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 */
char *malloc(int);
char *sock_strerror();
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *sock_errmsg(const char *descr) {
  int n = strlen(descr);
  const char *s = sock_strerror();
  char *msg = malloc(n + strlen(s) + 10);
  strcpy(msg, "ERROR! ");
  strcat(msg, descr);
  if (*s) {
    n += 7;
    msg[n] = ':';
    msg[n + 1] = ' ';
    strcpy(msg + n + 2, s);
  }
  return msg;
}


x86 assembly (clang, -O0):
<sock_errmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <sock_strerror@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
add    %eax,%edi
add    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11fb <sock_errmsg+0xab>
mov    -0xc(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_errmsg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <sock_strerror@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
cmpb   $0x0,(%r12)
je     11bf <sock_errmsg+0x6f>
movslq %r14d,%rax
movw   $0x203a,0x7(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rdi
add    $0x9,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"ERROR! \00"
define i8* @sock_errmsg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = call i8* (...) @sock_strerror()
store i8* %8, i8** %4
%9 = load i32, i32* %3
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = add nsw i32 %12, 10
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %5
%18 = load i8*, i8** %2
%19 = call i32 @strcat(i8* %17, i8* %18)
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %1
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 7
store i32 %25, i32* %3
%26 = load i8*, i8** %5
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 58, i8* %29
%30 = load i8*, i8** %5
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 32, i8* %34
%35 = load i8*, i8** %5
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %39, i8* %40)
br label %42
42: ; preds = %23, %1
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
@.str = [8 x i8] c"ERROR! \00"
define i8* @sock_errmsg(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* (...) @sock_strerror()
%4 = tail call i32 @strlen(i8* %3)
%5 = add i32 %2, 10
%6 = add i32 %5, %4
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %7, i8* %0)
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %1
%13 = add nsw i32 %2, 7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 58, i8* %15
%16 = add nsw i32 %2, 8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %7, i64 %17
store i8 32, i8* %18
%19 = getelementptr inbounds i8, i8* %15, i64 2
%20 = tail call i32 @strcpy(i8* %19, i8* %3)
br label %21
21: ; preds = %12, %1
ret i8* %7
}