void strncmpTest() {
  char str[][5] = {"R2D2", "C3PO", "R2A6", "AR25", "R3RE"};
  int n;
  puts("Looking for R2 astromech droids...");
  for (n = 0; n < 5; n++) {
    if (strncmp(str[n], "R2", 2) == 0) {
      printf("found %s\n", str[n]);
    }
  }
}


x86 assembly (clang, -O0):
<strncmpTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb9(%rip),%al
mov    %al,-0x8(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <puts@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    11da <strncmpTest+0xaa>
movslq -0x24(%rbp),%rax
lea    -0x20(%rbp),%rdi
imul   $0x5,%rax,%rax
add    %rax,%rdi
lea    0xea5(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c7 <strncmpTest+0x97>
movslq -0x24(%rbp),%rax
lea    -0x20(%rbp),%rsi
imul   $0x5,%rax,%rax
add    %rax,%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11cc <strncmpTest+0x9c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1177 <strncmpTest+0x47>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncmpTest>:
sub    $0x28,%rsp
movups 0xede(%rip),%xmm0
movups %xmm0,0x9(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed7(%rip),%rdi
xor    %eax,%eax
call   1030 <puts@plt>
movzwl (%rsp),%eax
cmp    $0x3252,%eax
jne    1165 <strncmpTest+0x45>
lea    0xee4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x5(%rsp),%eax
cmp    $0x3252,%eax
jne    1184 <strncmpTest+0x64>
lea    0x5(%rsp),%rsi
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xa(%rsp),%eax
cmp    $0x3252,%eax
jne    11a3 <strncmpTest+0x83>
lea    0xa(%rsp),%rsi
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xf(%rsp),%eax
cmp    $0x3252,%eax
jne    11c2 <strncmpTest+0xa2>
lea    0xf(%rsp),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x14(%rsp),%eax
cmp    $0x3252,%eax
jne    11e1 <strncmpTest+0xc1>
lea    0x14(%rsp),%rsi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.strncmpTest.str = [5 x [5 x i8]] [[5 x i8] c"R2D2\00", [5 x i8] c"C3PO\00", [5 x i8] c"R2A6\00", [5 x i8] c"AR25\00", [5 x i8] c"R3RE\00"]
@.str = [35 x i8] c"Looking for R2 astromech droids...\00"
@.str.1 = [3 x i8] c"R2\00"
@.str.2 = [10 x i8] c"found %s\0A\00"
define void @strncmpTest() {
%1 = alloca [5 x [5 x i8]]
%2 = alloca i32
%3 = bitcast [5 x [5 x i8]]* %1 to i8*
%4 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %5
5: ; preds = %22, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 %10
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%13 = call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 %17
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %18, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %15, %8
br label %22
22: ; preds = %21
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %5
25: ; preds = %5
ret void
}

LLVM IR (-O2):
@__const.strncmpTest.str = [5 x [5 x i8]] [[5 x i8] c"R2D2\00", [5 x i8] c"C3PO\00", [5 x i8] c"R2A6\00", [5 x i8] c"AR25\00", [5 x i8] c"R3RE\00"]
@.str = [35 x i8] c"Looking for R2 astromech droids...\00"
@.str.1 = [3 x i8] c"R2\00"
@.str.2 = [10 x i8] c"found %s\0A\00"
define void @strncmpTest() {
%1 = alloca [5 x [5 x i8]]
%2 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 0, i64 0
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [5 x [5 x i8]]* %1 to i16*
%5 = load i16, i16* %4
%6 = icmp eq i16 %5, 12882
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %9
9: ; preds = %0, %7
%10 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 1, i64 0
%11 = call i32 @bcmp(i8* dereferenceable(2) %10, i8* dereferenceable(2) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %15
15: ; preds = %13, %9
%16 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 2, i64 0
%17 = bitcast i8* %16 to i16*
%18 = load i16, i16* %17
%19 = icmp eq i16 %18, 12882
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %22
22: ; preds = %20, %15
%23 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 3, i64 0
%24 = call i32 @bcmp(i8* dereferenceable(2) %23, i8* dereferenceable(2) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %28
28: ; preds = %26, %22
%29 = getelementptr inbounds [5 x [5 x i8]], [5 x [5 x i8]]* %1, i64 0, i64 4, i64 0
%30 = bitcast i8* %29 to i16*
%31 = load i16, i16* %30
%32 = icmp eq i16 %31, 12882
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %35
35: ; preds = %33, %28
ret void
}