#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 sockaddr_in {
  int dummy;
};

/* Variables and functions */
char *strrchr(char *, char);
int to_sockaddr_in(char *, char *, struct sockaddr_in *);
int parse_address(char *s, struct sockaddr_in *a) {
  int ret = 0;
  char *c = strrchr(s, ':');
  if (c) {
    *c = 0;
    ret = to_sockaddr_in(s, c + 1, a);
    *c = ':';
  } else {
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<parse_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117f <parse_address+0x5f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rdx
call   1040 <to_sockaddr_in@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x3a,(%rax)
jmp    1186 <parse_address+0x66>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3a,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1157 <parse_address+0x37>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rsi
add    $0x1,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <to_sockaddr_in@plt>
movb   $0x3a,(%rbx)
jmp    115c <parse_address+0x3c>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
define i32 @parse_address(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 58)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8*, i8** %6
store i8 0, i8* %12
%13 = load i8*, i8** %3
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%17 = call i32 @to_sockaddr_in(i8* %13, i8* %15, %struct.sockaddr_in* %16)
store i32 %17, i32* %5
%18 = load i8*, i8** %6
store i8 58, i8* %18
br label %20
19: ; preds = %2
store i32 1, i32* %5
br label %20
20: ; preds = %19, %11
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
define i32 @parse_address(i8* %0, %struct.sockaddr_in* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
store i8 0, i8* %3
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i32 @to_sockaddr_in(i8* %0, i8* %6, %struct.sockaddr_in* %1)
store i8 58, i8* %3
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %7, %5 ], [ 1, %2 ]
ret i32 %9
}