#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*/ snprintf(char *, int, char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *longestCommonPrefix(char **strs, int strsSize) {
  if (!strsSize)
    return "";
  static char out[1024];
  int outlen;
  snprintf(out, 1024, "%s", strs[0]);
  outlen = strlen(out);
  int cnt = strsSize - 1;
  while (cnt) {
    if (strncmp(out, strs[cnt], outlen)) {
      char *a = out, *b = strs[cnt];
      while (*a == *b) {
        a++;
        b++;
      }
      *a = 0;
      outlen = strlen(out);
    }
    cnt--;
  }
  return out;
}


x86 assembly (clang, -O0):
<longestCommonPrefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1159 <longestCommonPrefix+0x29>
lea    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123c <longestCommonPrefix+0x10c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0x2ee9(%rip),%rdi
mov    $0x400,%esi
lea    0xe8d(%rip),%rdx
call   1050 <snprintf@plt>
lea    0x2ed1(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1231 <longestCommonPrefix+0x101>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
lea    0x2ea0(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1223 <longestCommonPrefix+0xf3>
lea    0x2e8a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    120d <longestCommonPrefix+0xdd>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11da <longestCommonPrefix+0xaa>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e35(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1190 <longestCommonPrefix+0x60>
lea    0x2e18(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longestCommonPrefix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     11d5 <longestCommonPrefix+0xa5>
mov    %esi,%r15d
mov    %rdi,%r14
mov    (%rdi),%rcx
lea    0x2f00(%rip),%r12
lea    0xea9(%rip),%rdx
mov    %r12,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%r15d
je     11dc <longestCommonPrefix+0xac>
mov    %eax,%ebp
movslq %r15d,%rbx
lea    0x2ed2(%rip),%r12
jmp    1195 <longestCommonPrefix+0x65>
movb   $0x0,(%rcx)
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0xffffffffffffffff,%rbx
test   %ebx,%ebx
je     11dc <longestCommonPrefix+0xac>
mov    (%r14,%rbx,8),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118d <longestCommonPrefix+0x5d>
mov    (%r14,%rbx,8),%rax
mov    0x2e9e(%rip),%dl
mov    %r12,%rcx
cmp    (%rax),%dl
jne    1180 <longestCommonPrefix+0x50>
add    $0x1,%rax
mov    %r12,%rcx
movzbl 0x1(%rcx),%edx
add    $0x1,%rcx
lea    0x1(%rax),%rsi
cmp    (%rax),%dl
mov    %rsi,%rax
je     11c0 <longestCommonPrefix+0x90>
jmp    1180 <longestCommonPrefix+0x50>
lea    0xe26(%rip),%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@longestCommonPrefix.out = internal global [1024 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i8* @longestCommonPrefix(i8** %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %59
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0))
store i32 %18, i32* %6
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %7
br label %21
21: ; preds = %55, %13
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %58
24: ; preds = %21
%25 = load i8**, i8*** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = load i32, i32* %6
%31 = call i64 @strncmp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i8* %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %55
33: ; preds = %24
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i8** %8
%34 = load i8**, i8*** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
store i8* %38, i8** %9
br label %39
39: ; preds = %47, %33
%40 = load i8*, i8** %8
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i8*, i8** %9
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %42, %45
br i1 %46, label %47, label %52
47: ; preds = %39
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %8
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
br label %39
52: ; preds = %39
%53 = load i8*, i8** %8
store i8 0, i8* %53
%54 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0))
store i32 %54, i32* %6
br label %55
55: ; preds = %52, %24
%56 = load i32, i32* %7
%57 = add nsw i32 %56, -1
store i32 %57, i32* %7
br label %21
58: ; preds = %21
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i8** %3
br label %59
59: ; preds = %58, %12
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@longestCommonPrefix.out = internal global [1024 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i8* @longestCommonPrefix(i8** nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %40, label %4
4: ; preds = %2
%5 = load i8*, i8** %0
%6 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0))
%8 = add i32 %1, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %40, label %10
10: ; preds = %4
%11 = sext i32 %8 to i64
br label %12
12: ; preds = %10, %35
%13 = phi i64 [ %11, %10 ], [ %37, %35 ]
%14 = phi i32 [ %7, %10 ], [ %36, %35 ]
%15 = getelementptr inbounds i8*, i8** %0, i64 %13
%16 = load i8*, i8** %15
%17 = tail call i64 @strncmp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), i8* %16, i32 %14)
%18 = icmp eq i64 %17, 0
br i1 %18, label %35, label %19
19: ; preds = %12
%20 = load i8*, i8** %15
%21 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0)
%22 = load i8, i8* %20
%23 = icmp eq i8 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %19, %24
%25 = phi i8* [ %28, %24 ], [ %20, %19 ]
%26 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), %19 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = getelementptr inbounds i8, i8* %25, i64 1
%29 = load i8, i8* %27
%30 = load i8, i8* %28
%31 = icmp eq i8 %29, %30
br i1 %31, label %24, label %32
32: ; preds = %24, %19
%33 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), %19 ], [ %27, %24 ]
store i8 0, i8* %33
%34 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0))
br label %35
35: ; preds = %32, %12
%36 = phi i32 [ %34, %32 ], [ %14, %12 ]
%37 = add nsw i64 %13, -1
%38 = trunc i64 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %12
40: ; preds = %35, %4, %2
%41 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), %4 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @longestCommonPrefix.out, i64 0, i64 0), %35 ]
ret i8* %41
}