#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 *, int, int, int, int);
int sscanf(char *, char *, int *, int *, int *, int *);
int reverse_domain_name(char *name) {
  int octet[4];
  int res;
  int idx;
  res = sscanf(name, "%d.%d.%d.%d", &octet[3], &octet[2], &octet[1], &octet[0]);
  for (idx = 0; idx < 4; idx++) {
    if (octet[idx] < 0 || octet[idx] > 255)
      return 1;
  }
  if (res == 4) {
    sprintf(name, "%d.%d.%d.%d", octet[0], octet[1], octet[2], octet[3]);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<reverse_domain_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
add    $0xc,%rdx
lea    -0x20(%rbp),%rcx
add    $0x8,%rcx
lea    -0x20(%rbp),%r8
add    $0x4,%r8
lea    -0x20(%rbp),%r9
lea    0xead(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11ac <reverse_domain_name+0x8c>
movslq -0x28(%rbp),%rax
cmpl   $0x0,-0x20(%rbp,%rax,4)
jl     118d <reverse_domain_name+0x6d>
movslq -0x28(%rbp),%rax
cmpl   $0xff,-0x20(%rbp,%rax,4)
jle    1199 <reverse_domain_name+0x79>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <reverse_domain_name+0xc7>
jmp    119e <reverse_domain_name+0x7e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1162 <reverse_domain_name+0x42>
cmpl   $0x4,-0x24(%rbp)
jne    11e0 <reverse_domain_name+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe31(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <reverse_domain_name+0xc7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_domain_name>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
lea    0xec2(%rip),%rsi
mov    %rsp,%r9
call   1030 <sscanf@plt>
mov    %eax,%esi
mov    (%rsp),%edx
mov    $0x1,%eax
cmp    $0xff,%edx
ja     1196 <reverse_domain_name+0x76>
mov    0x4(%rsp),%ecx
cmp    $0xff,%ecx
ja     1196 <reverse_domain_name+0x76>
mov    0x8(%rsp),%r8d
cmp    $0xff,%r8d
ja     1196 <reverse_domain_name+0x76>
mov    0xc(%rsp),%r9d
cmp    $0xff,%r9d
ja     1196 <reverse_domain_name+0x76>
cmp    $0x4,%esi
jne    1196 <reverse_domain_name+0x76>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @reverse_domain_name(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%12 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10, i32* %11)
store i32 %12, i32* %5
store i32 0, i32* %6
br label %13
13: ; preds = %30, %1
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = icmp slt i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp sgt i32 %26, 255
br i1 %27, label %28, label %29
28: ; preds = %22, %16
store i32 1, i32* %2
br label %48
29: ; preds = %22
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %13
33: ; preds = %13
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = load i8*, i8** %3
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%45 = load i32, i32* %44
%46 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %41, i32 %43, i32 %45)
store i32 0, i32* %2
br label %48
47: ; preds = %33
store i32 1, i32* %2
br label %48
48: ; preds = %47, %36, %28
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @reverse_domain_name(i8* nocapture %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6, i32* %7)
%9 = load i32, i32* %7
%10 = icmp ugt i32 %9, 255
br i1 %10, label %24, label %11
11: ; preds = %1
%12 = load i32, i32* %6
%13 = icmp ugt i32 %12, 255
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp ugt i32 %15, 255
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp ult i32 %18, 256
%20 = icmp eq i32 %8, 4
%21 = and i1 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12, i32 %15, i32 %18)
br label %24
24: ; preds = %1, %11, %14, %17, %22
%25 = phi i32 [ 0, %22 ], [ 1, %17 ], [ 1, %14 ], [ 1, %11 ], [ 1, %1 ]
ret i32 %25
}