#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 *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
int atm_decode_resnam(const char *in, char *chnm, char *resnm) {
  char *c;
  int i;
  if (!in) {
    *chnm = 0;
    *resnm = 0;
    return 0;
  }
  c = strchr(in, ':');
  if (c == NULL) {
    *chnm = 0;
    strcpy(resnm, in);
    return 1;
  }
  i = c - in;
  strncpy(chnm, in, i);
  chnm[i] = 0;
  c = strrchr(in, ':');
  i = c - in;
  strcpy(resnm, &in[i + 1]);
  return 1;
}


x86 assembly (clang, -O0):
<atm_decode_resnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <atm_decode_resnam+0x39>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    121f <atm_decode_resnam+0xdf>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b6 <atm_decode_resnam+0x76>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    121f <atm_decode_resnam+0xdf>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atm_decode_resnam>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     119e <atm_decode_resnam+0x5e>
mov    %rdi,%r12
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11aa <atm_decode_resnam+0x6a>
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r12,%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
sub    %r12d,%eax
add    $0x1,%eax
movslq %eax,%rsi
add    %r12,%rsi
mov    %r14,%rdi
jmp    11b4 <atm_decode_resnam+0x74>
movb   $0x0,(%r15)
movb   $0x0,(%r14)
xor    %eax,%eax
jmp    11be <atm_decode_resnam+0x7e>
movb   $0x0,(%r15)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @atm_decode_resnam(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i8*, i8** %6
store i8 0, i8* %13
%14 = load i8*, i8** %7
store i8 0, i8* %14
store i32 0, i32* %4
br label %55
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %6
store i8 0, i8* %21
%22 = load i8*, i8** %7
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
store i32 1, i32* %4
br label %55
25: ; preds = %15
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
store i32 %31, i32* %9
%32 = load i8*, i8** %6
%33 = load i8*, i8** %5
%34 = load i32, i32* %9
%35 = call i32 @strncpy(i8* %32, i8* %33, i32 %34)
%36 = load i8*, i8** %6
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %5
%41 = call i8* @strrchr(i8* %40, i8 signext 58)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = load i8*, i8** %5
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %9
%48 = load i8*, i8** %7
%49 = load i8*, i8** %5
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = call i32 @strcpy(i8* %48, i8* %53)
store i32 1, i32* %4
br label %55
55: ; preds = %25, %20, %12
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
define i32 @atm_decode_resnam(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %6
5: ; preds = %3
store i8 0, i8* %1
store i8 0, i8* %2
br label %28
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %0, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
store i8 0, i8* %1
%10 = tail call i32 @strcpy(i8* %2, i8* %0)
br label %28
11: ; preds = %6
%12 = ptrtoint i8* %7 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %15)
%17 = shl i64 %14, 32
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
%20 = tail call i8* @strrchr(i8* %0, i8 signext 58)
%21 = ptrtoint i8* %20 to i64
%22 = sub i64 %21, %13
%23 = shl i64 %22, 32
%24 = add i64 %23, 4294967296
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i32 @strcpy(i8* %2, i8* %26)
br label %28
28: ; preds = %11, %9, %5
%29 = phi i32 [ 1, %9 ], [ 1, %11 ], [ 0, %5 ]
ret i32 %29
}