#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tipc_addr(unsigned int, unsigned int, unsigned int);
uint32_t str2addr(char *str) {
  unsigned int z, c, n;
  char dummy;
  if (sscanf(str, "%u.%u.%u%c", &z, &c, &n, &dummy) != 3) {
    fprintf(stderr, "invalid network address, syntax: Z.C.N\n");
    return 0;
  }
  if (((z) <= (255) && (z) >= (0)) && ((c) <= (4095) && (c) >= (0)) &&
      ((n) <= (4095) && (n) >= (0)))
    return tipc_addr(z, c, n);
  fprintf(stderr, "invalid network address \"%s\"\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<str2addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
lea    -0x1d(%rbp),%r9
call   1050 <sscanf@plt>
cmp    $0x3,%eax
je     1188 <str2addr+0x58>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1205 <str2addr+0xd5>
cmpl   $0xff,-0x14(%rbp)
ja     11e3 <str2addr+0xb3>
cmpl   $0x0,-0x14(%rbp)
jb     11e3 <str2addr+0xb3>
cmpl   $0xfff,-0x18(%rbp)
ja     11e3 <str2addr+0xb3>
cmpl   $0x0,-0x18(%rbp)
jb     11e3 <str2addr+0xb3>
cmpl   $0xfff,-0x1c(%rbp)
ja     11e3 <str2addr+0xb3>
cmpl   $0x0,-0x1c(%rbp)
jb     11e3 <str2addr+0xb3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <tipc_addr@plt>
mov    %eax,-0x4(%rbp)
jmp    1205 <str2addr+0xd5>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2addr>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xec0(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0xb(%rsp),%r9
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    118b <str2addr+0x5b>
mov    0x14(%rsp),%edi
cmp    $0xff,%edi
ja     11a6 <str2addr+0x76>
mov    0x10(%rsp),%esi
cmp    $0xfff,%esi
ja     11a6 <str2addr+0x76>
mov    0xc(%rsp),%edx
cmp    $0xfff,%edx
ja     11a6 <str2addr+0x76>
call   1030 <tipc_addr@plt>
mov    %eax,%ebp
jmp    11c2 <str2addr+0x92>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11c2 <str2addr+0x92>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%u.%u.%u%c\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"invalid network address, syntax: Z.C.N\0A\00"
@.str.2 = [30 x i8] c"invalid network address \22%s\22\0A\00"
define i32 @str2addr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6, i8* %7)
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %41
14: ; preds = %1
%15 = load i32, i32* %4
%16 = icmp ule i32 %15, 255
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp uge i32 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp ule i32 %21, 4095
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp uge i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp ule i32 %27, 4095
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i32, i32* %6
%31 = icmp uge i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @tipc_addr(i32 %33, i32 %34, i32 %35)
store i32 %36, i32* %2
br label %41
37: ; preds = %29, %26, %23, %20, %17, %14
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %3
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %39)
store i32 0, i32* %2
br label %41
41: ; preds = %37, %32, %11
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [11 x i8] c"%u.%u.%u%c\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"invalid network address, syntax: Z.C.N\0A\00"
@.str.2 = [30 x i8] c"invalid network address \22%s\22\0A\00"
define i32 @str2addr(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i8* %5)
%10 = icmp eq i32 %9, 3
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %28
14: ; preds = %1
%15 = load i32, i32* %2
%16 = icmp ult i32 %15, 256
%17 = load i32, i32* %3
%18 = icmp ult i32 %17, 4096
%19 = select i1 %16, i1 %18, i1 false
%20 = load i32, i32* %4
%21 = icmp ult i32 %20, 4096
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @tipc_addr(i32 %15, i32 %17, i32 %20)
br label %28
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %25, %23, %11
%29 = phi i32 [ 0, %11 ], [ %24, %23 ], [ 0, %25 ]
ret i32 %29
}