#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*/ memcpy(char *, char *, int);
int snprintf(char *, int, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int make_dev_descr_resp(char *buf, int bufsz, char *ip, char *name, char *sn,
                        char *uuid) {
  int hdrlen, bodylen, taillen;
  char *bptr;
  char bodylenstr[20];
  hdrlen =
      snprintf(buf, bufsz - 1,
               "HTTP/1.1 200 OK\r\nDate: Fri, 02 Jan 1970 11:23:09 "
               "GMT\r\nServer: Unknown/0.0 UPnP/1.0 Virata-EmWeb/R6_0_1\r\n"
               "Transfer-Encoding: chunked\r\nContent-Type: "
               "text/xml\r\nExpires: Fri, 02 Jan 1970 11:23:09 GMT\r\n"
               "Last-Modified: Fri, 02 Jan 1970 11:23:09 GMT\r\nCache-Control: "
               "no-cache\r\nPragma: no-cache\r\n\r\n");
  bptr = buf + hdrlen + 10;
  bodylen = snprintf(
      bptr, bufsz - hdrlen - 10,
      "<?xml version=\"1.0\"?>\n\n\n"
      "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
      "    <specVersion>\n\t<major>1</major>\n\t<minor>0</minor>\n    "
      "</specVersion>\n"
      "    <URLBase>http://%s/</URLBase>\n"
      "    <device>\n"
      "\t<deviceType>urn:replaytv-com:device:ReplayDevice:1</deviceType>\n"
      "\t<friendlyName>%s</friendlyName>\n"
      "\t<modelDescription>ReplayTV 5000 Digital Video "
      "Recorder</modelDescription>\n"
      "\t<modelName>ReplayTV 5000</modelName>\n"
      "\t<modelNumber>5040</modelNumber>\n"
      "\t<version>530511440</version>\n"
      "\t<modelURL>http://www.sonicblue.com</modelURL>\n"
      "\t<manufacturer>SONICblue Incorporated</manufacturer>\n"
      "\t<manufacturerURL>http://www.sonicblue.com</manufacturerURL>\n"
      "\t<serialNumber>%s</serialNumber>\n"
      "\t<UDN> uuid:%s </UDN>\n"
      "\t<UPC>None</UPC>\n"
      "    </device>\n"
      "</root>\n",
      ip, name, sn, uuid);
  taillen = snprintf(bptr + bodylen, bufsz - hdrlen - bodylen - 10,
                     "\n\r\n0\r\n\r\n");
  sprintf(bodylenstr, "%08x\r\n", bodylen + 2);
  memcpy(buf + hdrlen, bodylenstr, 10);
  return (hdrlen + 10 + bodylen + taillen);
}


x86 assembly (clang, -O0):
<make_dev_descr_resp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xea0(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
add    $0xa,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    -0x34(%rbp),%esi
sub    $0xa,%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
lea    0xf7f(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
movslq -0x38(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x34(%rbp),%esi
sub    -0x38(%rbp),%esi
sub    $0xa,%esi
lea    0x1224(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%edx
add    $0x2,%edx
lea    0x1212(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   1040 <memcpy@plt>
mov    -0x34(%rbp),%eax
add    $0xa,%eax
add    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dev_descr_resp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbp
mov    %r8,0x8(%rsp)
mov    %rcx,%r15
mov    %rdx,%r13
mov    %esi,%ebx
mov    %rdi,%r14
lea    -0x1(%rbx),%esi
lea    0xea5(%rip),%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
movslq %eax,%r12
lea    (%r14,%r12,1),%rdi
add    $0xa,%rdi
add    %r12,%r14
mov    %ebx,%esi
sub    %r12d,%esi
add    $0xfffffff6,%esi
mov    %rbp,(%rsp)
lea    0xf9d(%rip),%rdx
mov    %r13,%rcx
mov    %r15,%r8
mov    0x8(%rsp),%r9
xor    %eax,%eax
call   1030 <snprintf@plt>
movslq %eax,%rbp
lea    (%r14,%rbp,1),%rdi
add    $0xa,%rdi
add    %ebp,%r12d
sub    %r12d,%ebx
add    $0xfffffff6,%ebx
lea    0x1241(%rip),%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %eax,%ebx
add    $0x2,%ebp
lea    0x1235(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1040 <memcpy@plt>
lea    (%rbx,%r12,1),%eax
add    $0xa,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [288 x i8] c"HTTP/1.1 200 OK\0D\0ADate: Fri, 02 Jan 1970 11:23:09 GMT\0D\0AServer: Unknown/0.0 UPnP/1.0 Virata-EmWeb/R6_0_1\0D\0ATransfer-Encoding: chunked\0D\0AContent-Type: text/xml\0D\0AExpires: Fri, 02 Jan 1970 11:23:09 GMT\0D\0ALast-Modified: Fri, 02 Jan 1970 11:23:09 GMT\0D\0ACache-Control: no-cache\0D\0APragma: no-cache\0D\0A\0D\0A\00"
@.str.1 = [721 x i8] c"<?xml version=\221.0\22?>\0A\0A\0A<root xmlns=\22urn:schemas-upnp-org:device-1-0\22>\0A <specVersion>\0A\09<major>1</major>\0A\09<minor>0</minor>\0A </specVersion>\0A <URLBase>http://%s/</URLBase>\0A <device>\0A\09<deviceType>urn:replaytv-com:device:ReplayDevice:1</deviceType>\0A\09<friendlyName>%s</friendlyName>\0A\09<modelDescription>ReplayTV 5000 Digital Video Recorder</modelDescription>\0A\09<modelName>ReplayTV 5000</modelName>\0A\09<modelNumber>5040</modelNumber>\0A\09<version>530511440</version>\0A\09<modelURL>http://www.sonicblue.com</modelURL>\0A\09<manufacturer>SONICblue Incorporated</manufacturer>\0A\09<manufacturerURL>http://www.sonicblue.com</manufacturerURL>\0A\09<serialNumber>%s</serialNumber>\0A\09<UDN> uuid:%s </UDN>\0A\09<UPC>None</UPC>\0A </device>\0A</root>\0A\00"
@.str.2 = [9 x i8] c"\0A\0D\0A0\0D\0A\0D\0A\00"
@.str.3 = [7 x i8] c"%08x\0D\0A\00"
define i32 @make_dev_descr_resp(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca [20 x i8]
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%18 = load i8*, i8** %7
%19 = load i32, i32* %8
%20 = sub nsw i32 %19, 1
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 %20, i8* getelementptr inbounds ([288 x i8], [288 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %13
%22 = load i8*, i8** %7
%23 = load i32, i32* %13
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 10
store i8* %26, i8** %16
%27 = load i8*, i8** %16
%28 = load i32, i32* %8
%29 = load i32, i32* %13
%30 = sub nsw i32 %28, %29
%31 = sub nsw i32 %30, 10
%32 = load i8*, i8** %9
%33 = load i8*, i8** %10
%34 = load i8*, i8** %11
%35 = load i8*, i8** %12
%36 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %27, i32 %31, i8* getelementptr inbounds ([721 x i8], [721 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33, i8* %34, i8* %35)
store i32 %36, i32* %14
%37 = load i8*, i8** %16
%38 = load i32, i32* %14
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i32, i32* %8
%42 = load i32, i32* %13
%43 = sub nsw i32 %41, %42
%44 = load i32, i32* %14
%45 = sub nsw i32 %43, %44
%46 = sub nsw i32 %45, 10
%47 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %40, i32 %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %47, i32* %15
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%49 = load i32, i32* %14
%50 = add nsw i32 %49, 2
%51 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load i8*, i8** %7
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%57 = call i32 @memcpy(i8* %55, i8* %56, i32 10)
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 10
%60 = load i32, i32* %14
%61 = add nsw i32 %59, %60
%62 = load i32, i32* %15
%63 = add nsw i32 %61, %62
ret i32 %63
}

LLVM IR (-O2):
@.str = [288 x i8] c"HTTP/1.1 200 OK\0D\0ADate: Fri, 02 Jan 1970 11:23:09 GMT\0D\0AServer: Unknown/0.0 UPnP/1.0 Virata-EmWeb/R6_0_1\0D\0ATransfer-Encoding: chunked\0D\0AContent-Type: text/xml\0D\0AExpires: Fri, 02 Jan 1970 11:23:09 GMT\0D\0ALast-Modified: Fri, 02 Jan 1970 11:23:09 GMT\0D\0ACache-Control: no-cache\0D\0APragma: no-cache\0D\0A\0D\0A\00"
@.str.1 = [721 x i8] c"<?xml version=\221.0\22?>\0A\0A\0A<root xmlns=\22urn:schemas-upnp-org:device-1-0\22>\0A <specVersion>\0A\09<major>1</major>\0A\09<minor>0</minor>\0A </specVersion>\0A <URLBase>http://%s/</URLBase>\0A <device>\0A\09<deviceType>urn:replaytv-com:device:ReplayDevice:1</deviceType>\0A\09<friendlyName>%s</friendlyName>\0A\09<modelDescription>ReplayTV 5000 Digital Video Recorder</modelDescription>\0A\09<modelName>ReplayTV 5000</modelName>\0A\09<modelNumber>5040</modelNumber>\0A\09<version>530511440</version>\0A\09<modelURL>http://www.sonicblue.com</modelURL>\0A\09<manufacturer>SONICblue Incorporated</manufacturer>\0A\09<manufacturerURL>http://www.sonicblue.com</manufacturerURL>\0A\09<serialNumber>%s</serialNumber>\0A\09<UDN> uuid:%s </UDN>\0A\09<UPC>None</UPC>\0A </device>\0A</root>\0A\00"
@.str.2 = [9 x i8] c"\0A\0D\0A0\0D\0A\0D\0A\00"
@.str.3 = [7 x i8] c"%08x\0D\0A\00"
define i32 @make_dev_descr_resp(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%9 = add nsw i32 %1, -1
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %9, i8* getelementptr inbounds ([288 x i8], [288 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 10
%14 = sub nsw i32 %1, %10
%15 = add nsw i32 %14, -10
%16 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 %15, i8* getelementptr inbounds ([721 x i8], [721 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3, i8* %4, i8* %5)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = sub i32 -10, %16
%20 = add i32 %19, %14
%21 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = add nsw i32 %16, 2
%23 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @memcpy(i8* %12, i8* %8, i32 10)
%25 = add nsw i32 %10, 10
%26 = add nsw i32 %25, %16
%27 = add nsw i32 %26, %21
ret i32 %27
}