#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 /*<<< orphan*/ osm_write_tag(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ xfree(char *);
char *xstrdup(char const *);
void osm_write_opt_tag(const char *atag) {
  char *tag, *cin, *ce;
  if (!atag)
    return;
  tag = cin = xstrdup(atag);
  ce = cin + strlen(cin);
  while (cin < ce) {
    char *sc, *dp;
    if ((sc = strchr(cin, ';')))
      *sc = '\0';
    if ((dp = strchr(cin, ':'))) {
      *dp++ = '\0';
      osm_write_tag(cin, dp);
    }
    cin += strlen(cin) + 1;
  }
  xfree(tag);
}


x86 assembly (clang, -O0):
<osm_write_opt_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116c <osm_write_opt_tag+0x1c>
jmp    1234 <osm_write_opt_tag+0xe4>
mov    -0x8(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    122b <osm_write_opt_tag+0xdb>
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11cf <osm_write_opt_tag+0x7f>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     120a <osm_write_opt_tag+0xba>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <osm_write_tag@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    119e <osm_write_opt_tag+0x4e>
mov    -0x10(%rbp),%rdi
call   1050 <xfree@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osm_write_opt_tag>:
test   %rdi,%rdi
je     11de <osm_write_opt_tag+0x8e>
push   %r15
push   %r14
push   %rbx
call   1060 <xstrdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d1 <osm_write_opt_tag+0x81>
cltq
mov    %r14,%r15
add    %rax,%r15
mov    %r14,%rbx
jmp    1196 <osm_write_opt_tag+0x46>
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
cmp    %r15,%rbx
jae    11d1 <osm_write_opt_tag+0x81>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ab <osm_write_opt_tag+0x5b>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <osm_write_opt_tag+0x30>
mov    %rax,%rsi
add    $0x1,%rsi
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1070 <osm_write_tag@plt>
jmp    1180 <osm_write_opt_tag+0x30>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <xfree@plt>
ret

LLVM IR (-O0):
define void @osm_write_opt_tag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
br label %49
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i8* @xstrdup(i8* %12)
store i8* %13, i8** %4
store i8* %13, i8** %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8* %18, i8** %5
br label %19
19: ; preds = %39, %11
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = icmp ult i8* %20, %21
br i1 %22, label %23, label %46
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = call i8* @strchr(i8* %24, i8 signext 59)
store i8* %25, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i8*, i8** %6
store i8 0, i8* %28
br label %29
29: ; preds = %27, %23
%30 = load i8*, i8** %4
%31 = call i8* @strchr(i8* %30, i8 signext 58)
store i8* %31, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %7
store i8 0, i8* %34
%36 = load i8*, i8** %4
%37 = load i8*, i8** %7
%38 = call i32 @osm_write_tag(i8* %36, i8* %37)
br label %39
39: ; preds = %33, %29
%40 = load i8*, i8** %4
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = load i8*, i8** %4
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8* %45, i8** %4
br label %19
46: ; preds = %19
%47 = load i8*, i8** %3
%48 = call i32 @xfree(i8* %47)
br label %49
49: ; preds = %46, %10
ret void
}

LLVM IR (-O2):
define void @osm_write_opt_tag(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = tail call i8* @xstrdup(i8* %0)
%5 = tail call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %26
9: ; preds = %3, %20
%10 = phi i8* [ %24, %20 ], [ %4, %3 ]
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 59)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %9
store i8 0, i8* %11
br label %14
14: ; preds = %13, %9
%15 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %15
%19 = tail call i32 @osm_write_tag(i8* %10, i8* %18)
br label %20
20: ; preds = %17, %14
%21 = tail call i32 @strlen(i8* %10)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %10, i64 %23
%25 = icmp ult i8* %24, %7
br i1 %25, label %9, label %26
26: ; preds = %20, %3
%27 = tail call i32 @xfree(i8* %4)
br label %28
28: ; preds = %1, %26
ret void
}