#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 selstr(char *, char const *);
int /*<<< orphan*/ strncmp(char *, char const *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void selwr(char *s1, const char *s2, size_t mxl) {
  int rc = 0;
  if (!strncmp(s1, s2, mxl))
    return;
  do
    rc = selstr(s1, s2);
  while (rc != 1 && rc != 2);
  if (rc == 2)
    strncpy(s1, s2, mxl);
}


x86 assembly (clang, -O0):
<selwr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    116a <selwr+0x3a>
jmp    11be <selwr+0x8e>
jmp    116f <selwr+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <selstr@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
je     1198 <selwr+0x68>
cmpl   $0x2,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    116f <selwr+0x3f>
cmpl   $0x2,-0x1c(%rbp)
jne    11be <selwr+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selwr>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strncmp@plt>
test   %eax,%eax
je     117b <selwr+0x4b>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <selstr@plt>
lea    -0x3(%rax),%ecx
cmp    $0xfffffffe,%ecx
jb     1150 <selwr+0x20>
cmp    $0x2,%eax
jne    117b <selwr+0x4b>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @selwr(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = call i32 @strncmp(i8* %8, i8* %9, i64 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
br label %35
14: ; preds = %3
br label %15
15: ; preds = %25, %14
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 @selstr(i8* %16, i8* %17)
store i32 %18, i32* %7
br label %19
19: ; preds = %15
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 2
br label %25
25: ; preds = %22, %19
%26 = phi i1 [ false, %19 ], [ %24, %22 ]
br i1 %26, label %15, label %27
27: ; preds = %25
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = load i64, i64* %6
%34 = call i32 @strncpy(i8* %31, i8* %32, i64 %33)
br label %35
35: ; preds = %13, %30, %27
ret void
}

LLVM IR (-O2):
define void @selwr(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @strncmp(i8* %0, i8* %1, i64 %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3, %6
%7 = tail call i32 @selstr(i8* %0, i8* %1)
%8 = add i32 %7, -3
%9 = icmp ult i32 %8, -2
br i1 %9, label %6, label %10
10: ; preds = %6
%11 = icmp eq i32 %7, 2
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @strncpy(i8* %0, i8* %1, i64 %2)
br label %14
14: ; preds = %10, %12, %3
ret void
}