#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 */
char *get_ipv6_addr();
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ putchar(char const);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
void print_ipv6_info(const char *format_up, const char *format_down) {
  const char *walk;
  char *addr_string = get_ipv6_addr();
  if (addr_string == NULL) {
    printf("%s", format_down);
  } else {
    for (walk = format_up; *walk != '\0'; walk++) {
      if (*walk != '%') {
        putchar(*walk);
        continue;
      }
      if (strncmp(walk + 1, "ip", strlen("ip")) == 0) {
        printf("%s", addr_string);
        walk += strlen("ip");
      }
    }
  }
}


x86 assembly (clang, -O0):
<print_ipv6_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <get_ipv6_addr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <print_ipv6_info+0x3b>
mov    -0x10(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1070 <printf@plt>
jmp    123f <print_ipv6_info+0xef>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123a <print_ipv6_info+0xea>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
je     11c4 <print_ipv6_info+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1229 <print_ipv6_info+0xd9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    0xe2c(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe1a(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1224 <print_ipv6_info+0xd4>
mov    -0x20(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1070 <printf@plt>
lea    0xdf4(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1229 <print_ipv6_info+0xd9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1193 <print_ipv6_info+0x43>
jmp    123f <print_ipv6_info+0xef>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ipv6_info>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <get_ipv6_addr@plt>
test   %rax,%rax
je     11df <print_ipv6_info+0x8f>
mov    %rax,%r14
lea    0xe8e(%rip),%r15
lea    0xe84(%rip),%r12
jmp    11a2 <print_ipv6_info+0x52>
xchg   %ax,%ax
lea    0x1(%rbx),%r13
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11bb <print_ipv6_info+0x6b>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
je     1180 <print_ipv6_info+0x30>
test   %al,%al
je     11d5 <print_ipv6_info+0x85>
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
jmp    11a2 <print_ipv6_info+0x52>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
add    %rax,%rbx
jmp    119e <print_ipv6_info+0x4e>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe1a(%rip),%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"ip\00"
define void @print_ipv6_info(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = call i8* (...) @get_ipv6_addr()
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %47
13: ; preds = %2
%14 = load i8*, i8** %3
store i8* %14, i8** %5
br label %15
15: ; preds = %43, %13
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 37
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = call i32 @putchar(i8 signext %27)
br label %43
29: ; preds = %20
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%33 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = load i8*, i8** %5
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %5
br label %42
42: ; preds = %35, %29
br label %43
43: ; preds = %42, %25
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
br label %15
46: ; preds = %15
br label %47
47: ; preds = %46, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"ip\00"
define void @print_ipv6_info(i8* %0, i8* %1) {
%3 = tail call i8* (...) @get_ipv6_addr()
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %25
7: ; preds = %2, %22
%8 = phi i8* [ %24, %22 ], [ %0, %2 ]
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 0, label %25
i8 37, label %12
]
10: ; preds = %7
%11 = tail call i32 @putchar(i8 signext %9)
br label %22
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %8, i64 %20
br label %22
22: ; preds = %12, %17, %10
%23 = phi i8* [ %8, %10 ], [ %21, %17 ], [ %8, %12 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
br label %7
25: ; preds = %7, %5
ret void
}