#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int ieee1888_soap_error_gen(const char *error_msg, char *str_soap, int n) {
  int len;
  char *p = str_soap;
  strncpy(p,
          "<?xml version=\'1.0\' encoding=\'UTF-8\'?><soapenv:Envelope "
          "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/"
          "\"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</"
          "faultcode><faultstring>",
          n);
  len = strlen(p);
  n -= len;
  p += len;
  if (n <= 0) {
    return -2;
  }
  strncpy(p, error_msg, n);
  len = strlen(p);
  n -= len;
  p += len;
  if (n <= 0) {
    return -2;
  }
  strncpy(p,
          "</faultstring><detail "
          "/></soapenv:Fault></soapenv:Body></soapenv:Envelope>",
          n);
  len = strlen(p);
  n -= len;
  p += len;
  if (n <= 0) {
    return -2;
  }
  return strlen(str_soap);
}


x86 assembly (clang, -O0):
<ieee1888_soap_error_gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xeb7(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     118c <ieee1888_soap_error_gen+0x6c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1237 <ieee1888_soap_error_gen+0x117>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11da <ieee1888_soap_error_gen+0xba>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1237 <ieee1888_soap_error_gen+0x117>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xeda(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     122b <ieee1888_soap_error_gen+0x10b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1237 <ieee1888_soap_error_gen+0x117>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ieee1888_soap_error_gen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeca(%rip),%rsi
mov    %r14,%rdi
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
jle    119d <ieee1888_soap_error_gen+0x7d>
movslq %eax,%rbx
add    %r14,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
jle    119d <ieee1888_soap_error_gen+0x7d>
cltq
add    %rax,%rbx
lea    0xf4d(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jle    119d <ieee1888_soap_error_gen+0x7d>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlen@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [194 x i8] c"<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\22http://schemas.xmlsoap.org/soap/envelope/\22><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>\00"
@.str.1 = [75 x i8] c"</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope>\00"
define i32 @ieee1888_soap_error_gen(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
store i8* %10, i8** %9
%11 = load i8*, i8** %9
%12 = load i32, i32* %7
%13 = call i32 @strncpy(i8* %11, i8* getelementptr inbounds ([194 x i8], [194 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %9
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, %16
store i32 %18, i32* %7
%19 = load i32, i32* %8
%20 = load i8*, i8** %9
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %9
%23 = load i32, i32* %7
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
store i32 -2, i32* %4
br label %62
26: ; preds = %3
%27 = load i8*, i8** %9
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %9
%32 = call i32 @strlen(i8* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %7
%36 = load i32, i32* %8
%37 = load i8*, i8** %9
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %9
%40 = load i32, i32* %7
%41 = icmp sle i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %26
store i32 -2, i32* %4
br label %62
43: ; preds = %26
%44 = load i8*, i8** %9
%45 = load i32, i32* %7
%46 = call i32 @strncpy(i8* %44, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %9
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %7
%52 = load i32, i32* %8
%53 = load i8*, i8** %9
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8* %55, i8** %9
%56 = load i32, i32* %7
%57 = icmp sle i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %43
store i32 -2, i32* %4
br label %62
59: ; preds = %43
%60 = load i8*, i8** %6
%61 = call i32 @strlen(i8* %60)
store i32 %61, i32* %4
br label %62
62: ; preds = %59, %58, %42, %25
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
@.str = [194 x i8] c"<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\22http://schemas.xmlsoap.org/soap/envelope/\22><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>\00"
@.str.1 = [75 x i8] c"</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope>\00"
define i32 @ieee1888_soap_error_gen(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([194 x i8], [194 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = tail call i32 @strlen(i8* %1)
%6 = sub nsw i32 %2, %5
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = icmp slt i32 %6, 1
br i1 %9, label %23, label %10
10: ; preds = %3
%11 = tail call i32 @strncpy(i8* %8, i8* %0, i32 %6)
%12 = tail call i32 @strlen(i8* %8)
%13 = sub nsw i32 %6, %12
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = icmp slt i32 %13, 1
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = tail call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%19 = tail call i32 @strlen(i8* %15)
%20 = icmp sgt i32 %13, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @strlen(i8* %1)
br label %23
23: ; preds = %17, %10, %3, %21
%24 = phi i32 [ %22, %21 ], [ -2, %3 ], [ -2, %10 ], [ -2, %17 ]
ret i32 %24
}