#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 */
struct trace_seq {
  int dummy;
};
struct print_arg {
  int dummy;
};
struct event_format {
  int dummy;
};

/* Variables and functions */
int print_ipsa_arg(struct trace_seq *, char const *, char, void *, int,
                   struct event_format *, struct print_arg *);
int print_ipv4_arg(struct trace_seq *, char const *, char, void *, int,
                   struct event_format *, struct print_arg *);
int print_ipv6_arg(struct trace_seq *, char const *, char, void *, int,
                   struct event_format *, struct print_arg *);
int print_ip_arg(struct trace_seq *s, const char *ptr, void *data, int size,
                 struct event_format *event, struct print_arg *arg) {
  char i = *ptr;
  char ver;
  int rc = 0;
  ptr++;
  rc++;
  ver = *ptr;
  ptr++;
  rc++;
  switch (ver) {
  case '4':
    rc += print_ipv4_arg(s, ptr, i, data, size, event, arg);
    break;
  case '6':
    rc += print_ipv6_arg(s, ptr, i, data, size, event, arg);
    break;
  case 'S':
    rc += print_ipsa_arg(s, ptr, i, data, size, event, arg);
    break;
  default:
    return 0;
  }
  return rc;
}


x86 assembly (clang, -O0):
<print_ip_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x3a(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
movsbl -0x3a(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x34,%eax
je     11c9 <print_ip_arg+0x99>
jmp    11a7 <print_ip_arg+0x77>
mov    -0x44(%rbp),%eax
sub    $0x36,%eax
je     11fb <print_ip_arg+0xcb>
jmp    11b8 <print_ip_arg+0x88>
mov    -0x44(%rbp),%eax
sub    $0x53,%eax
je     122d <print_ip_arg+0xfd>
jmp    125f <print_ip_arg+0x12f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x39(%rbp),%dl
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
movsbl %dl,%edx
mov    %rax,(%rsp)
call   1040 <print_ipv4_arg@plt>
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    126b <print_ip_arg+0x13b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x39(%rbp),%dl
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
movsbl %dl,%edx
mov    %rax,(%rsp)
call   1030 <print_ipv6_arg@plt>
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    126b <print_ip_arg+0x13b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x39(%rbp),%dl
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
movsbl %dl,%edx
mov    %rax,(%rsp)
call   1050 <print_ipsa_arg@plt>
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    126b <print_ip_arg+0x13b>
movl   $0x0,-0x4(%rbp)
jmp    1271 <print_ip_arg+0x141>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ip_arg>:
push   %rax
mov    %r8,%r10
mov    %ecx,%r8d
mov    %rdx,%r11
mov    (%rsi),%dl
movsbl 0x1(%rsi),%ecx
add    $0x2,%rsi
cmp    $0x53,%ecx
je     1169 <print_ip_arg+0x39>
cmp    $0x36,%ecx
je     117d <print_ip_arg+0x4d>
xor    %eax,%eax
cmp    $0x34,%ecx
jne    1192 <print_ip_arg+0x62>
mov    %r9,(%rsp)
movsbl %dl,%edx
mov    %r11,%rcx
mov    %r10,%r9
call   1040 <print_ipv4_arg@plt>
jmp    118f <print_ip_arg+0x5f>
mov    %r9,(%rsp)
movsbl %dl,%edx
mov    %r11,%rcx
mov    %r10,%r9
call   1050 <print_ipsa_arg@plt>
jmp    118f <print_ip_arg+0x5f>
mov    %r9,(%rsp)
movsbl %dl,%edx
mov    %r11,%rcx
mov    %r10,%r9
call   1030 <print_ipv6_arg@plt>
add    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.event_format = type { i32 }
%struct.print_arg = type { i32 }
define i32 @print_ip_arg(%struct.trace_seq* %0, i8* %1, i8* %2, i32 %3, %struct.event_format* %4, %struct.print_arg* %5) {
%7 = alloca i32
%8 = alloca %struct.trace_seq*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.event_format*
%13 = alloca %struct.print_arg*
%14 = alloca i8
%15 = alloca i8
%16 = alloca i32
store %struct.trace_seq* %0, %struct.trace_seq** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store %struct.event_format* %4, %struct.event_format** %12
store %struct.print_arg* %5, %struct.print_arg** %13
%17 = load i8*, i8** %9
%18 = load i8, i8* %17
store i8 %18, i8* %14
store i32 0, i32* %16
%19 = load i8*, i8** %9
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %9
%21 = load i32, i32* %16
%22 = add nsw i32 %21, 1
store i32 %22, i32* %16
%23 = load i8*, i8** %9
%24 = load i8, i8* %23
store i8 %24, i8* %15
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
%27 = load i32, i32* %16
%28 = add nsw i32 %27, 1
store i32 %28, i32* %16
%29 = load i8, i8* %15
%30 = sext i8 %29 to i32
switch i32 %30, label %64 [
i32 52, label %31
i32 54, label %42
i32 83, label %53
]
31: ; preds = %6
%32 = load %struct.trace_seq*, %struct.trace_seq** %8
%33 = load i8*, i8** %9
%34 = load i8, i8* %14
%35 = load i8*, i8** %10
%36 = load i32, i32* %11
%37 = load %struct.event_format*, %struct.event_format** %12
%38 = load %struct.print_arg*, %struct.print_arg** %13
%39 = call i32 @print_ipv4_arg(%struct.trace_seq* %32, i8* %33, i8 signext %34, i8* %35, i32 %36, %struct.event_format* %37, %struct.print_arg* %38)
%40 = load i32, i32* %16
%41 = add nsw i32 %40, %39
store i32 %41, i32* %16
br label %65
42: ; preds = %6
%43 = load %struct.trace_seq*, %struct.trace_seq** %8
%44 = load i8*, i8** %9
%45 = load i8, i8* %14
%46 = load i8*, i8** %10
%47 = load i32, i32* %11
%48 = load %struct.event_format*, %struct.event_format** %12
%49 = load %struct.print_arg*, %struct.print_arg** %13
%50 = call i32 @print_ipv6_arg(%struct.trace_seq* %43, i8* %44, i8 signext %45, i8* %46, i32 %47, %struct.event_format* %48, %struct.print_arg* %49)
%51 = load i32, i32* %16
%52 = add nsw i32 %51, %50
store i32 %52, i32* %16
br label %65
53: ; preds = %6
%54 = load %struct.trace_seq*, %struct.trace_seq** %8
%55 = load i8*, i8** %9
%56 = load i8, i8* %14
%57 = load i8*, i8** %10
%58 = load i32, i32* %11
%59 = load %struct.event_format*, %struct.event_format** %12
%60 = load %struct.print_arg*, %struct.print_arg** %13
%61 = call i32 @print_ipsa_arg(%struct.trace_seq* %54, i8* %55, i8 signext %56, i8* %57, i32 %58, %struct.event_format* %59, %struct.print_arg* %60)
%62 = load i32, i32* %16
%63 = add nsw i32 %62, %61
store i32 %63, i32* %16
br label %65
64: ; preds = %6
store i32 0, i32* %7
br label %67
65: ; preds = %53, %42, %31
%66 = load i32, i32* %16
store i32 %66, i32* %7
br label %67
67: ; preds = %65, %64
%68 = load i32, i32* %7
ret i32 %68
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.event_format = type { i32 }
%struct.print_arg = type { i32 }
define i32 @print_ip_arg(%struct.trace_seq* %0, i8* %1, i8* %2, i32 %3, %struct.event_format* %4, %struct.print_arg* %5) {
%7 = load i8, i8* %1
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = sext i8 %9 to i32
switch i32 %11, label %21 [
i32 52, label %12
i32 54, label %14
i32 83, label %16
]
12: ; preds = %6
%13 = tail call i32 @print_ipv4_arg(%struct.trace_seq* %0, i8* %10, i8 signext %7, i8* %2, i32 %3, %struct.event_format* %4, %struct.print_arg* %5)
br label %18
14: ; preds = %6
%15 = tail call i32 @print_ipv6_arg(%struct.trace_seq* %0, i8* %10, i8 signext %7, i8* %2, i32 %3, %struct.event_format* %4, %struct.print_arg* %5)
br label %18
16: ; preds = %6
%17 = tail call i32 @print_ipsa_arg(%struct.trace_seq* %0, i8* %10, i8 signext %7, i8* %2, i32 %3, %struct.event_format* %4, %struct.print_arg* %5)
br label %18
18: ; preds = %16, %14, %12
%19 = phi i32 [ %17, %16 ], [ %15, %14 ], [ %13, %12 ]
%20 = add nsw i32 %19, 2
br label %21
21: ; preds = %6, %18
%22 = phi i32 [ %20, %18 ], [ 0, %6 ]
ret i32 %22
}