#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__ uint64_t;

/* Variables and functions */
scalar_t__ UINT64_MAX;
scalar_t__ be64toh(scalar_t__);
scalar_t__ htobe64(scalar_t__);
int /*<<< orphan*/ memcpy(void *, scalar_t__ *, int);
void ip6_incr(void *address) {
  uint64_t addr[2];
  memcpy(addr, address, 16);
  addr[0] = be64toh(addr[0]);
  addr[1] = be64toh(addr[1]);
  if (addr[1] == UINT64_MAX) {
    addr[0] += 1;
    addr[1] = 0;
  } else {
    addr[1] += 1;
  }
  addr[0] = htobe64(addr[0]);
  addr[1] = htobe64(addr[1]);
  memcpy(address, addr, 16);
}


x86 assembly (clang, -O0):
<ip6_incr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <be64toh@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <be64toh@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    1195 <ip6_incr+0x65>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    11a1 <ip6_incr+0x71>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <htobe64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <htobe64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip6_incr>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    (%rsp),%rdi
call   1030 <be64toh@plt>
mov    %rax,(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <be64toh@plt>
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    117b <ip6_incr+0x4b>
mov    (%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,(%rsp)
xor    %eax,%eax
jmp    1183 <ip6_incr+0x53>
add    $0x1,%rax
mov    (%rsp),%rdi
mov    %rax,0x8(%rsp)
call   1050 <htobe64@plt>
mov    %rax,(%rsp)
mov    0x8(%rsp),%rdi
call   1050 <htobe64@plt>
mov    %rax,0x8(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@UINT64_MAX = global i64 0
define void @ip6_incr(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i64]
store i8* %0, i8** %2
%4 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%5 = bitcast i64* %4 to i8*
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i64*
%8 = call i32 @memcpy(i8* %5, i64* %7, i32 16)
%9 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%10 = load i64, i64* %9
%11 = call i64 @be64toh(i64 %10)
%12 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
store i64 %11, i64* %12
%13 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%14 = load i64, i64* %13
%15 = call i64 @be64toh(i64 %14)
%16 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
store i64 %15, i64* %16
%17 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%18 = load i64, i64* %17
%19 = load i64, i64* @UINT64_MAX
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %1
%22 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%23 = load i64, i64* %22
%24 = add nsw i64 %23, 1
store i64 %24, i64* %22
%25 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
store i64 0, i64* %25
br label %30
26: ; preds = %1
%27 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%28 = load i64, i64* %27
%29 = add nsw i64 %28, 1
store i64 %29, i64* %27
br label %30
30: ; preds = %26, %21
%31 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%32 = load i64, i64* %31
%33 = call i64 @htobe64(i64 %32)
%34 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
store i64 %33, i64* %34
%35 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%36 = load i64, i64* %35
%37 = call i64 @htobe64(i64 %36)
%38 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
store i64 %37, i64* %38
%39 = load i8*, i8** %2
%40 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%41 = call i32 @memcpy(i8* %39, i64* %40, i32 16)
ret void
}

LLVM IR (-O2):
@UINT64_MAX = global i64 0
define void @ip6_incr(i8* %0) {
%2 = alloca [2 x i64]
%3 = bitcast [2 x i64]* %2 to i8*
%4 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 0
%5 = bitcast i8* %0 to i64*
%6 = call i32 @memcpy(i8* %3, i64* %5, i32 16)
%7 = load i64, i64* %4
%8 = call i64 @be64toh(i64 %7)
store i64 %8, i64* %4
%9 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 1
%10 = load i64, i64* %9
%11 = call i64 @be64toh(i64 %10)
%12 = load i64, i64* @UINT64_MAX
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i64, i64* %4
%16 = add nsw i64 %15, 1
store i64 %16, i64* %4
br label %20
17: ; preds = %1
%18 = add nsw i64 %11, 1
%19 = load i64, i64* %4
br label %20
20: ; preds = %17, %14
%21 = phi i64 [ %19, %17 ], [ %16, %14 ]
%22 = phi i64 [ %18, %17 ], [ 0, %14 ]
store i64 %22, i64* %9
%23 = call i64 @htobe64(i64 %21)
store i64 %23, i64* %4
%24 = load i64, i64* %9
%25 = call i64 @htobe64(i64 %24)
store i64 %25, i64* %9
%26 = call i32 @memcpy(i8* %0, i64* %4, i32 16)
ret void
}