#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 */
int sscanf(char const *, char *, unsigned int *);
char *strchr(char const *, char);
char *strrchr(char const *, char);
unsigned int extract_port(const char *s) {
  const char *p, *t;
  unsigned int pno;
  int i;
  if (!s || !*s) {
    return 0;
  }
  if (!(p = strrchr(s, '@'))) {
    return 0;
  }
  if (!(t = strchr(p, ':'))) {
    t = strchr(p, ',');
  }
  if (!t) {
    return 0;
  }
  i = sscanf(t, "%u", &pno);
  if (i != 1) {
    return 0;
  }
  return pno;
}


x86 assembly (clang, -O0):
<extract_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1154 <extract_port+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1160 <extract_port+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1200 <extract_port+0xd0>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1188 <extract_port+0x58>
movl   $0x0,-0x4(%rbp)
jmp    1200 <extract_port+0xd0>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b6 <extract_port+0x86>
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cd <extract_port+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    1200 <extract_port+0xd0>
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     11fa <extract_port+0xca>
movl   $0x0,-0x4(%rbp)
jmp    1200 <extract_port+0xd0>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_port>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1195 <extract_port+0x65>
cmpb   $0x0,(%rdi)
je     1195 <extract_port+0x65>
mov    $0x40,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1195 <extract_port+0x65>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1176 <extract_port+0x46>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1195 <extract_port+0x65>
lea    0xe83(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <sscanf@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    1195 <extract_port+0x65>
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
define i32 @extract_port(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %1
store i32 0, i32* %2
br label %39
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i8* @strrchr(i8* %16, i8 signext 64)
store i8* %17, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 0, i32* %2
br label %39
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i8* @strchr(i8* %21, i8 signext 58)
store i8* %22, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = call i8* @strchr(i8* %25, i8 signext 44)
store i8* %26, i8** %5
br label %27
27: ; preds = %24, %20
%28 = load i8*, i8** %5
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %27
store i32 0, i32* %2
br label %39
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 0, i32* %2
br label %39
37: ; preds = %31
%38 = load i32, i32* %6
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %36, %30, %19, %14
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @extract_port(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = tail call i8* @strrchr(i8* %0, i8 signext 64)
%10 = icmp eq i8* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = tail call i8* @strchr(i8* %9, i8 signext 58)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i8* @strchr(i8* %9, i8 signext 44)
%16 = icmp eq i8* %15, null
br i1 %16, label %23, label %17
17: ; preds = %11, %14
%18 = phi i8* [ %15, %14 ], [ %12, %11 ]
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%20 = icmp eq i32 %19, 1
%21 = load i32, i32* %2
%22 = select i1 %20, i32 %21, i32 0
br label %23
23: ; preds = %17, %14, %8, %1, %5
%24 = phi i32 [ 0, %5 ], [ 0, %1 ], [ 0, %8 ], [ 0, %14 ], [ %22, %17 ]
ret i32 %24
}