#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 */
typedef int u_int32_t;
typedef int /*<<< orphan*/ quad;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
char *numtoquad(u_int32_t num) {
  int a[4], i;
  static char quad[17];
  for (i = 0; i < 4; i++)
    a[i] = num >> (8 * (3 - i)) & 0xff;
  snprintf(quad, sizeof(quad), "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
  return quad;
}


x86 assembly (clang, -O0):
<numtoquad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    115a <numtoquad+0x4a>
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
sub    -0x24(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1122 <numtoquad+0x12>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0x2ed1(%rip),%rdi
mov    $0x11,%esi
lea    0xe85(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
lea    0x2eb6(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numtoquad>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ecx
mov    %edi,%eax
movzbl %ch,%ebp
movzbl %cl,%edx
shr    $0x18,%ecx
shr    $0x10,%eax
movzbl %al,%r8d
mov    %edx,(%rsp)
lea    0x2f0f(%rip),%rbx
lea    0xec8(%rip),%rdx
mov    %rbx,%rdi
mov    $0x11,%esi
mov    %ebp,%r9d
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@numtoquad.quad = internal global [17 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @numtoquad(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %4
%11 = sub nsw i32 3, %10
%12 = mul nsw i32 8, %11
%13 = ashr i32 %9, %12
%14 = and i32 %13, 255
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %16
store i32 %14, i32* %17
br label %18
18: ; preds = %8
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%29 = load i32, i32* %28
%30 = call i32 @snprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %25, i32 %27, i32 %29)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0)
}

LLVM IR (-O2):
@numtoquad.quad = internal global [17 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @numtoquad(i32 %0) {
%2 = lshr i32 %0, 24
%3 = lshr i32 %0, 16
%4 = and i32 %3, 255
%5 = lshr i32 %0, 8
%6 = and i32 %5, 255
%7 = and i32 %0, 255
%8 = tail call i32 @snprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %4, i32 %6, i32 %7)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0)
}