#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 scalar_t__ uint;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ delimit(scalar_t__, int /*<<< orphan*/, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, scalar_t__ *, scalar_t__ *, scalar_t__ *, char *);
int /*<<< orphan*/ tipc_addr(scalar_t__, scalar_t__, scalar_t__);
__u32 str2addr(char *str) {
  uint z, c, n;
  char dummy;
  if (sscanf(str, "%u.%u.%u%c", &z, &c, &n, &dummy) != 3)
    do {
      printf("invalid network address, use syntax: Z.C.N\n");
      exit(EXIT_FAILURE);
    } while (0);
  if ((z != delimit(z, 0, 255)) || (c != delimit(c, 0, 4095)) ||
      (n != delimit(n, 0, 4095)))
    do {
      printf("network address field value(s) too large\n");
      exit(EXIT_FAILURE);
    } while (0);
  return tipc_addr(z, c, n);
}


x86 assembly (clang, -O0):
<str2addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x21(%rbp),%r9
call   1060 <sscanf@plt>
cmp    $0x3,%eax
je     11a4 <str2addr+0x54>
jmp    118a <str2addr+0x3a>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <delimit@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    121c <str2addr+0xcc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xfff,%edx
call   1030 <delimit@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jne    121c <str2addr+0xcc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xfff,%edx
call   1030 <delimit@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     123b <str2addr+0xeb>
jmp    1221 <str2addr+0xd1>
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <tipc_addr@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2addr>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x7(%rsp),%r9
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    11e8 <str2addr+0x98>
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <delimit@plt>
cmp    %rax,%rbx
jne    11df <str2addr+0x8f>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfff,%edx
call   1040 <delimit@plt>
cmp    %rax,%rbx
jne    11df <str2addr+0x8f>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfff,%edx
call   1040 <delimit@plt>
cmp    %rax,%rbx
jne    11df <str2addr+0x8f>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   1050 <tipc_addr@plt>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe25(%rip),%rdi
jmp    11ef <str2addr+0x9f>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"%u.%u.%u%c\00"
@EXIT_FAILURE = global i32 0
@str = [41 x i8] c"network address field value(s) too large\00"
@str.3 = [43 x i8] c"invalid network address, use syntax: Z.C.N\00"
define i32 @str2addr(i8* nocapture %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3, i64* %4, i8* %5)
%10 = icmp eq i32 %9, 3
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i64, i64* %2
%17 = call i64 @delimit(i64 %16, i32 0, i32 255)
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i64, i64* %3
%21 = call i64 @delimit(i64 %20, i32 0, i32 4095)
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i64, i64* %4
%25 = call i64 @delimit(i64 %24, i32 0, i32 4095)
%26 = icmp eq i64 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %15, %19, %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = load i64, i64* %2
%33 = load i64, i64* %3
%34 = load i64, i64* %4
%35 = call i32 @tipc_addr(i64 %32, i64 %33, i64 %34)
ret i32 %35
}