#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *getIPString(struct sockaddr_in *client) {
  char *buff;
  buff = malloc(sizeof(char) * 20);
  if (buff == NULL)
    return NULL;
  sprintf(buff, "%d.%d.%d.%d", (int)(client->sin_addr.s_addr & 0xFF),
          (int)((client->sin_addr.s_addr & 0xFF00) >> 8),
          (int)((client->sin_addr.s_addr & 0xFF0000) >> 16),
          (int)((client->sin_addr.s_addr & 0xFF000000) >> 24));
  return buff;
}


x86 assembly (clang, -O0):
<getIPString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x14,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1152 <getIPString+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <getIPString+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8d
and    $0xff0000,%r8d
sar    $0x10,%r8d
mov    -0x10(%rbp),%rax
mov    (%rax),%r9d
and    $0xff000000,%r9d
shr    $0x18,%r9d
lea    0xe64(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIPString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x14,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1160 <getIPString+0x40>
mov    (%r14),%eax
movzbl %al,%edx
movzbl %ah,%ecx
mov    %eax,%esi
shr    $0x10,%esi
movzbl %sil,%r8d
shr    $0x18,%eax
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%r9d
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @getIPString(%struct.sockaddr_in* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in*
%4 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
%5 = call i8* @malloc(i32 20)
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %36
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, 255
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, 65280
%21 = ashr i32 %20, 8
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, 16711680
%27 = ashr i32 %26, 16
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %28, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, -16777216
%33 = lshr i32 %32, 24
%34 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %21, i32 %27, i32 %33)
%35 = load i8*, i8** %4
store i8* %35, i8** %2
br label %36
36: ; preds = %9, %8
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define noalias i8* @getIPString(%struct.sockaddr_in* nocapture %0) {
%2 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0, i32 0
%6 = load i32, i32* %5
%7 = and i32 %6, 255
%8 = lshr i32 %6, 8
%9 = and i32 %8, 255
%10 = lshr i32 %6, 16
%11 = and i32 %10, 255
%12 = lshr i32 %6, 24
%13 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %11, i32 %12)
br label %14
14: ; preds = %1, %4
ret i8* %2
}