#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*/ strcat(char *, char *);
int strlen(char *);
int upnp_strcat(char *what, char *where, int bytes_left) {
  if (!what)
    return bytes_left;
  if (strlen(what) < bytes_left) {
    strcat(where, what);
    return bytes_left - strlen(what);
  }
  return bytes_left;
}


x86 assembly (clang, -O0):
<upnp_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <upnp_strcat+0x29>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <upnp_strcat+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jge    1186 <upnp_strcat+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    118c <upnp_strcat+0x6c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upnp_strcat>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
test   %rdi,%rdi
je     114f <upnp_strcat+0x2f>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %ebp,%eax
jge    114f <upnp_strcat+0x2f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @upnp_strcat(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = load i32, i32* %7
store i32 %11, i32* %4
br label %27
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = load i32, i32* %7
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 %21, %23
store i32 %24, i32* %4
br label %27
25: ; preds = %12
%26 = load i32, i32* %7
store i32 %26, i32* %4
br label %27
27: ; preds = %25, %17, %10
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @upnp_strcat(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, %2
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @strcat(i8* %1, i8* %0)
%10 = tail call i32 @strlen(i8* %0)
%11 = sub nsw i32 %2, %10
br label %12
12: ; preds = %5, %3, %8
%13 = phi i32 [ %11, %8 ], [ %2, %3 ], [ %2, %5 ]
ret i32 %13
}