#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 */
typedef int /*<<< orphan*/ w;
typedef int /*<<< orphan*/ s4;
typedef int /*<<< orphan*/ s3;
typedef int /*<<< orphan*/ s2;
typedef int /*<<< orphan*/ s1;

/* Variables and functions */
int /*<<< orphan*/ stpncpy(char *, char const *, int);
scalar_t__ strncasecmp(char const *, char const *, int);
int /*<<< orphan*/ strncat(char *, char const *, int);
scalar_t__ strncmp(char const *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strndup(char const *, int);
int f4(char *x, char **y, int z, char w[64]) {
  const char *s1 = "foobarbaz";
  const char *s2 = "abcde12345678";
  strncpy(x, s1, sizeof(s1));
  strncat(x, s2, sizeof(s2));
  stpncpy(x, s1, sizeof(s1));
  y[0] = strndup(s1, sizeof(s1));
  z += strncmp(s1, s2, sizeof(s1));
  z += strncmp(s1, s2, sizeof(s2));
  z += strncasecmp(s1, s2, sizeof(s1));
  z += strncasecmp(s1, s2, sizeof(s2));
  strncpy(w, s1, sizeof(w));
  strncat(w, s2, sizeof(w));
  stpncpy(w, s1, sizeof(w));
  const char s3[] = "foobarbaz";
  const char s4[] = "abcde12345678";
  strncpy(x, s3, sizeof(s3));
  strncat(x, s4, sizeof(s4));
  stpncpy(x, s3, sizeof(s3));
  y[1] = strndup(s3, sizeof(s3));
  z += strncmp(s3, s4, sizeof(s3));
  z += strncmp(s3, s4, sizeof(s4));
  z += strncasecmp(s3, s4, sizeof(s3));
  z += strncasecmp(s3, s4, sizeof(s4));
  return z;
}


x86 assembly (clang, -O0):
<f4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <stpncpy@plt>
mov    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1060 <strndup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <stpncpy@plt>
mov    0xd6c(%rip),%rax
mov    %rax,-0x3a(%rbp)
mov    0xd69(%rip),%ax
mov    %ax,-0x32(%rbp)
mov    0xd60(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xd5e(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xd58(%rip),%ax
mov    %ax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xe,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
mov    $0xa,%edx
call   1080 <stpncpy@plt>
lea    -0x3a(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strndup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
lea    -0x3a(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    -0x3a(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xe,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    -0x3a(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    -0x3a(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xe,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %edx,0xc(%rsp)
mov    %rsi,%rbp
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbx
lea    0xe79(%rip),%r12
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0xe6f(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1080 <stpncpy@plt>
mov    %r12,%rdi
mov    $0x8,%esi
call   1060 <strndup@plt>
mov    %rax,0x0(%rbp)
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %rax,%r14
add    0xc(%rsp),%r14d
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %rax,%rbp
add    %r14d,%ebp
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1070 <strncasecmp@plt>
lea    0x0(%rbp,%rax,2),%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1080 <stpncpy@plt>
movabs $0x61627261626f6f66,%rax
72 62 61
mov    %rax,0x10(%rsp)
movw   $0x7a,0x18(%rsp)
movabs $0x38373635343332,%rax
mov    %rax,0x2e(%rsp)
movabs $0x3332316564636261,%rax
31 32 33
mov    %rax,0x28(%rsp)
lea    0x10(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
lea    0x28(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xe,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1080 <stpncpy@plt>
mov    %r15,%rdi
mov    $0xa,%esi
call   1060 <strndup@plt>
mov    0x20(%rsp),%rcx
mov    %rax,0x8(%rcx)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xe,%edx
call   1040 <strncmp@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <strncasecmp@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xe,%edx
call   1070 <strncasecmp@plt>
add    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"foobarbaz\00"
@.str.1 = [14 x i8] c"abcde12345678\00"
@__const.f4.s3 = [10 x i8] c"foobarbaz\00"
@__const.f4.s4 = [14 x i8] c"abcde12345678\00"
define i32 @f4(i8* %0, i8** %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [10 x i8]
%12 = alloca [14 x i8]
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %10
%13 = load i8*, i8** %5
%14 = load i8*, i8** %9
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 8)
%16 = load i8*, i8** %5
%17 = load i8*, i8** %10
%18 = call i32 @strncat(i8* %16, i8* %17, i32 8)
%19 = load i8*, i8** %5
%20 = load i8*, i8** %9
%21 = call i32 @stpncpy(i8* %19, i8* %20, i32 8)
%22 = load i8*, i8** %9
%23 = call i8* @strndup(i8* %22, i32 8)
%24 = load i8**, i8*** %6
%25 = getelementptr inbounds i8*, i8** %24, i64 0
store i8* %23, i8** %25
%26 = load i8*, i8** %9
%27 = load i8*, i8** %10
%28 = call i64 @strncmp(i8* %26, i8* %27, i32 8)
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %7
%33 = load i8*, i8** %9
%34 = load i8*, i8** %10
%35 = call i64 @strncmp(i8* %33, i8* %34, i32 8)
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = add nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %7
%40 = load i8*, i8** %9
%41 = load i8*, i8** %10
%42 = call i64 @strncasecmp(i8* %40, i8* %41, i32 8)
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
%47 = load i8*, i8** %9
%48 = load i8*, i8** %10
%49 = call i64 @strncasecmp(i8* %47, i8* %48, i32 8)
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %7
%54 = load i8*, i8** %8
%55 = load i8*, i8** %9
%56 = call i32 @strncpy(i8* %54, i8* %55, i32 8)
%57 = load i8*, i8** %8
%58 = load i8*, i8** %10
%59 = call i32 @strncat(i8* %57, i8* %58, i32 8)
%60 = load i8*, i8** %8
%61 = load i8*, i8** %9
%62 = call i32 @stpncpy(i8* %60, i8* %61, i32 8)
%63 = bitcast [10 x i8]* %11 to i8*
%64 = bitcast [14 x i8]* %12 to i8*
%65 = load i8*, i8** %5
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%67 = call i32 @strncpy(i8* %65, i8* %66, i32 10)
%68 = load i8*, i8** %5
%69 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%70 = call i32 @strncat(i8* %68, i8* %69, i32 14)
%71 = load i8*, i8** %5
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%73 = call i32 @stpncpy(i8* %71, i8* %72, i32 10)
%74 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%75 = call i8* @strndup(i8* %74, i32 10)
%76 = load i8**, i8*** %6
%77 = getelementptr inbounds i8*, i8** %76, i64 1
store i8* %75, i8** %77
%78 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%79 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%80 = call i64 @strncmp(i8* %78, i8* %79, i32 10)
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = add nsw i64 %82, %80
%84 = trunc i64 %83 to i32
store i32 %84, i32* %7
%85 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%86 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%87 = call i64 @strncmp(i8* %85, i8* %86, i32 14)
%88 = load i32, i32* %7
%89 = sext i32 %88 to i64
%90 = add nsw i64 %89, %87
%91 = trunc i64 %90 to i32
store i32 %91, i32* %7
%92 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%93 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%94 = call i64 @strncasecmp(i8* %92, i8* %93, i32 10)
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = add nsw i64 %96, %94
%98 = trunc i64 %97 to i32
store i32 %98, i32* %7
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%100 = getelementptr inbounds [14 x i8], [14 x i8]* %12, i64 0, i64 0
%101 = call i64 @strncasecmp(i8* %99, i8* %100, i32 14)
%102 = load i32, i32* %7
%103 = sext i32 %102 to i64
%104 = add nsw i64 %103, %101
%105 = trunc i64 %104 to i32
store i32 %105, i32* %7
%106 = load i32, i32* %7
ret i32 %106
}

LLVM IR (-O2):
@__const.f4.s3 = [10 x i8] c"foobarbaz\00"
@__const.f4.s4 = [14 x i8] c"abcde12345678\00"
define i32 @f4(i8* %0, i8** nocapture writeonly %1, i32 %2, i8* %3) {
%5 = alloca [10 x i8]
%6 = alloca [14 x i8]
%7 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i32 8)
%8 = tail call i32 @strncat(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.f4.s4, i64 0, i64 0), i32 8)
%9 = tail call i32 @stpncpy(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i32 8)
%10 = tail call dereferenceable_or_null(9) i8* @strndup(i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i32 8)
store i8* %10, i8** %1
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.f4.s4, i64 0, i64 0), i32 8)
%12 = trunc i64 %11 to i32
%13 = add i32 %12, %2
%14 = tail call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.f4.s4, i64 0, i64 0), i32 8)
%15 = trunc i64 %14 to i32
%16 = add i32 %13, %15
%17 = tail call i64 @strncasecmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.f4.s4, i64 0, i64 0), i32 8)
%18 = trunc i64 %17 to i32
%19 = shl i32 %18, 1
%20 = add i32 %16, %19
%21 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i32 8)
%22 = tail call i32 @strncat(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__const.f4.s4, i64 0, i64 0), i32 8)
%23 = tail call i32 @stpncpy(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__const.f4.s3, i64 0, i64 0), i32 8)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%26 = call i32 @strncpy(i8* %0, i8* %24, i32 10)
%27 = call i32 @strncat(i8* %0, i8* %25, i32 14)
%28 = call i32 @stpncpy(i8* %0, i8* %24, i32 10)
%29 = call i8* @strndup(i8* %24, i32 10)
%30 = getelementptr inbounds i8*, i8** %1, i64 1
store i8* %29, i8** %30
%31 = call i64 @strncmp(i8* %24, i8* %25, i32 10)
%32 = trunc i64 %31 to i32
%33 = add i32 %20, %32
%34 = call i64 @strncmp(i8* %24, i8* %25, i32 14)
%35 = trunc i64 %34 to i32
%36 = add i32 %33, %35
%37 = call i64 @strncasecmp(i8* %24, i8* %25, i32 10)
%38 = trunc i64 %37 to i32
%39 = add i32 %36, %38
%40 = call i64 @strncasecmp(i8* %24, i8* %25, i32 14)
%41 = trunc i64 %40 to i32
%42 = add i32 %39, %41
ret i32 %42
}