#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*/ bzero(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
char *numtoquad(u_int32_t num) {
  int a[4], x;
  static char quad[17];
  for (x = 0; x < 4; x++)
    a[x] = num >> (8 * (3 - x)) & 0xff;
  bzero((char *)quad, sizeof(quad));
  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    116a <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    1132 <numtoquad+0x12>
lea    0x2ecf(%rip),%rdi
mov    $0x11,%esi
call   1040 <bzero@plt>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0x2eb0(%rip),%rdi
mov    $0x11,%esi
lea    0xe64(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
lea    0x2e95(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numtoquad>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %edi,%eax
movzbl %bh,%ecx
mov    %ecx,%r12d
movzbl %bl,%ebp
shr    $0x18,%ebx
shr    $0x10,%eax
movzbl %al,%r15d
lea    0x2ef6(%rip),%r14
mov    %r14,%rdi
mov    $0x11,%esi
call   1040 <bzero@plt>
mov    %ebp,(%rsp)
lea    0xe9f(%rip),%rdx
mov    %ebx,%ecx
mov    %r14,%rdi
mov    $0x11,%esi
mov    %r15d,%r8d
mov    %r12d,%r9d
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = call i32 @bzero(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0), i32 17)
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%28 = load i32, i32* %27
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%30 = load i32, i32* %29
%31 = 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 %24, i32 %26, i32 %28, i32 %30)
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 @bzero(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @numtoquad.quad, i64 0, i64 0), i32 17)
%9 = 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)
}