#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, *tmp;
  tmp = malloc(sizeof(char) * 20);
  if (tmp == NULL)
    return NULL;
  buff = tmp;
  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));
  tmp = NULL;
  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,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1152 <getIPString+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <getIPString+0x99>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
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    0xe5c(%rip),%rsi
call   1040 <sprintf@plt>
movq   $0x0,-0x20(%rbp)
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*
%5 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
%6 = call i8* @malloc(i32 20)
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %38
10: ; preds = %1
%11 = load i8*, i8** %5
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, 255
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, 65280
%23 = ashr i32 %22, 8
%24 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %27, 16711680
%29 = ashr i32 %28, 16
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, -16777216
%35 = lshr i32 %34, 24
%36 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %23, i32 %29, i32 %35)
store i8* null, i8** %5
%37 = load i8*, i8** %4
store i8* %37, i8** %2
br label %38
38: ; preds = %10, %9
%39 = load i8*, i8** %2
ret i8* %39
}

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
}