#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*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *printoctets(unsigned char *octets, int length) {
  static char stroctets[64];
  int i;
  stroctets[0] = '\0';
  for (i = 0; i < length; i++) {
    sprintf(stroctets + strlen(stroctets), "%u", octets[i]);
    if (i + 1 < length)
      strcat(stroctets, ".");
  }
  return stroctets;
}


x86 assembly (clang, -O0):
<printoctets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,0x2f0a(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <printoctets+0x8e>
lea    0x2ef0(%rip),%rdi
call   1030 <strlen@plt>
cltq
lea    0x2ee2(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe80(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    11ab <printoctets+0x7b>
lea    0x2eb1(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcat@plt>
jmp    11b0 <printoctets+0x80>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <printoctets+0x1d>
lea    0x2e8b(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printoctets>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x2f0e(%rip)
test   %esi,%esi
jle    11b4 <printoctets+0x84>
mov    %rdi,%r14
mov    %esi,%r13d
mov    %r13,%rbp
neg    %rbp
mov    $0x1,%r12d
lea    0x2ef1(%rip),%rbx
lea    0xe9a(%rip),%r15
jmp    1182 <printoctets+0x52>
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%r12
cmp    $0x1,%rax
je     11b4 <printoctets+0x84>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
movzbl -0x1(%r14,%r12,1),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
cmp    %r13,%r12
jae    1170 <printoctets+0x40>
mov    %rbx,%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcat@plt>
jmp    1170 <printoctets+0x40>
lea    0x2e95(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@printoctets.stroctets = internal global [64 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
@.str.1 = [2 x i8] c".\00"
define i8* @printoctets(i8* nocapture %0, i32 %1) {
store i8 0, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @printoctets.stroctets, i64 0, i64 0)
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %4, %19
%8 = phi i64 [ 0, %4 ], [ %15, %19 ]
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @printoctets.stroctets, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [64 x i8], [64 x i8]* @printoctets.stroctets, i64 0, i64 %10
%12 = getelementptr inbounds i8, i8* %0, i64 %8
%13 = load i8, i8* %12
%14 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%15 = add nuw nsw i64 %8, 1
%16 = icmp ult i64 %15, %5
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 @strcat(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @printoctets.stroctets, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %7, %17
%20 = icmp eq i64 %15, %6
br i1 %20, label %21, label %7
21: ; preds = %19, %2
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @printoctets.stroctets, i64 0, i64 0)
}