#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*/ printf(char *, unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
int bin2ip(unsigned int ip, char *str) {
  unsigned char *ptr = (char *)&ip, i, *res = str;
  char ch[4];
  for (i = 1; i <= 4; i++) {
    sprintf(ch, "%d.", *ptr);
    strcat(str, ch);
    ptr = ptr + 1;
  }
  printf("%s", res);
}


x86 assembly (clang, -O0):
<bin2ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movb   $0x1,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x4,%eax
jg     119d <bin2ip+0x6d>
lea    -0x2c(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe91(%rip),%rsi
movzbl (%rax),%edx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1153 <bin2ip+0x23>
mov    -0x28(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
mov    %edi,%r12d
shr    $0x10,%r12d
mov    %edi,%r13d
shr    $0x18,%r13d
movzbl %bl,%edx
lea    0xea8(%rip),%r15
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
movzbl %bh,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
movzbl %r12b,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
lea    0xe3e(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d.\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @bin2ip(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca [4 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = bitcast i32* %4 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %5
store i8* %11, i8** %8
store i8 1, i8* %7
br label %12
12: ; preds = %26, %2
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = icmp sle i32 %14, 4
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
%21 = load i8*, i8** %5
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %6
br label %26
26: ; preds = %16
%27 = load i8, i8* %7
%28 = add i8 %27, 1
store i8 %28, i8* %7
br label %12
29: ; preds = %12
%30 = load i8*, i8** %8
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d.\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @bin2ip(i32 %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = trunc i32 %0 to i8
%5 = lshr i32 %0, 8
%6 = trunc i32 %5 to i8
%7 = lshr i32 %0, 16
%8 = trunc i32 %7 to i8
%9 = lshr i32 %0, 24
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %4)
%13 = call i32 @strcat(i8* %1, i8* %11)
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
%15 = call i32 @strcat(i8* %1, i8* %11)
%16 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %8)
%17 = call i32 @strcat(i8* %1, i8* %11)
%18 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%19 = call i32 @strcat(i8* %1, i8* %11)
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
ret i32 undef
}