#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*/ isalpha(char);
scalar_t__ isdigit(char);
int /*<<< orphan*/ luaI_addchar(char);
int /*<<< orphan*/ luaI_addquoted(char *);
int lua_check_number(int /*<<< orphan*/, char *);
char *lua_check_string(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lua_error(char *);
int /*<<< orphan*/ lua_pushstring(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
void str_format(void) {
  int arg = 1;
  char *strfrmt = lua_check_string(arg++, "format");
  luaI_addchar(0);
  while (*strfrmt) {
    if (*strfrmt != '%')
      luaI_addchar(*strfrmt++);
    else if (*++strfrmt == '%')
      luaI_addchar(*strfrmt++);
    else {
      char form[50];
      char buff[2000];
      int size = 0;
      int i = 0;
      form[i++] = '%';
      form[i] = *strfrmt++;
      while (!isalpha(form[i])) {
        if (isdigit(form[i])) {
          size = size * 10 + form[i] - '0';
          if (size >= 2000)
            lua_error("format size/precision too long in function `format'");
        } else if (form[i] == '.')
          size = 0;
        if (++i >= 50)
          lua_error("bad format in function `format'");
        form[i] = *strfrmt++;
      }
      form[i + 1] = 0;
      switch (form[i]) {
      case 'q':
        luaI_addquoted(lua_check_string(arg++, "format"));
        buff[0] = '\0';
        break;
      case 's': {
        char *s = lua_check_string(arg++, "format");
        if (strlen(s) >= 2000)
          lua_error("string argument too long in function `format'");
        sprintf(buff, form, s);
        break;
      }
      case 'c':
      case 'd':
      case 'i':
      case 'o':
      case 'u':
      case 'x':
      case 'X':
        sprintf(buff, form, (int)lua_check_number(arg++, "format"));
        break;
      case 'e':
      case 'E':
      case 'f':
      case 'g':
        sprintf(buff, form, lua_check_number(arg++, "format"));
        break;
      default:
        lua_error("invalid format option in function `format'");
      }
      for (i = 0; buff[i]; i++)
        luaI_addchar(buff[i]);
    }
  }
  lua_pushstring(luaI_addchar(0));
}


x86 assembly (clang, -O0):
<str_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xf0c(%rip),%rsi
call   1050 <lua_check_string@plt>
mov    %rax,-0x10(%rbp)
xor    %edi,%edi
call   1070 <luaI_addchar@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1542 <str_format+0x3a2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
je     120d <str_format+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1070 <luaI_addchar@plt>
jmp    153d <str_format+0x39d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    1245 <str_format+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1070 <luaI_addchar@plt>
jmp    1538 <str_format+0x398>
movl   $0x0,-0x824(%rbp)
movl   $0x0,-0x828(%rbp)
mov    -0x828(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x828(%rbp)
cltq
movb   $0x25,-0x50(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
movslq -0x828(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
movslq -0x828(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%edi
call   1090 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12b3 <str_format+0x113>
jmp    1376 <str_format+0x1d6>
movslq -0x828(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     130d <str_format+0x16d>
imul   $0xa,-0x824(%rbp),%eax
movslq -0x828(%rbp),%rcx
movsbl -0x50(%rbp,%rcx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x824(%rbp)
cmpl   $0x7d0,-0x824(%rbp)
jl     1308 <str_format+0x168>
lea    0xdd4(%rip),%rdi
call   10a0 <lua_error@plt>
jmp    1331 <str_format+0x191>
movslq -0x828(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x2e,%eax
jne    132c <str_format+0x18c>
movl   $0x0,-0x824(%rbp)
jmp    1331 <str_format+0x191>
mov    -0x828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x828(%rbp)
cmp    $0x32,%eax
jl     1355 <str_format+0x1b5>
lea    0xdbb(%rip),%rdi
call   10a0 <lua_error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
movslq -0x828(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
jmp    128d <str_format+0xed>
movslq -0x828(%rbp),%rax
lea    -0x50(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
movslq -0x828(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
add    $0xffffffbb,%eax
mov    %eax,%ecx
mov    %rcx,-0x838(%rbp)
sub    $0x33,%eax
ja     14e0 <str_format+0x340>
mov    -0x838(%rbp),%rax
lea    0xc4b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xd00(%rip),%rsi
call   1050 <lua_check_string@plt>
mov    %rax,%rdi
call   1080 <luaI_addquoted@plt>
movb   $0x0,-0x820(%rbp)
jmp    14ec <str_format+0x34c>
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xcd5(%rip),%rsi
call   1050 <lua_check_string@plt>
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x7d0,%eax
jl     142a <str_format+0x28a>
lea    0xd06(%rip),%rdi
call   10a0 <lua_error@plt>
lea    -0x820(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x830(%rbp),%rdx
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    14ec <str_format+0x34c>
lea    -0x820(%rbp),%rax
mov    %rax,-0x848(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xc5d(%rip),%rsi
call   1030 <lua_check_number@plt>
mov    -0x848(%rbp),%rdi
mov    -0x840(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    14ec <str_format+0x34c>
lea    -0x820(%rbp),%rax
mov    %rax,-0x858(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x850(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xc11(%rip),%rsi
call   1030 <lua_check_number@plt>
mov    -0x858(%rbp),%rdi
mov    -0x850(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    14ec <str_format+0x34c>
lea    0xc72(%rip),%rdi
call   10a0 <lua_error@plt>
movl   $0x0,-0x828(%rbp)
movslq -0x828(%rbp),%rax
cmpb   $0x0,-0x820(%rbp,%rax,1)
je     1533 <str_format+0x393>
movslq -0x828(%rbp),%rax
movsbl -0x820(%rbp,%rax,1),%edi
ff
call   1070 <luaI_addchar@plt>
mov    -0x828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x828(%rbp)
jmp    14f6 <str_format+0x356>
jmp    1538 <str_format+0x398>
jmp    153d <str_format+0x39d>
jmp    11d4 <str_format+0x34>
xor    %edi,%edi
call   1070 <luaI_addchar@plt>
mov    %eax,%edi
call   10c0 <lua_pushstring@plt>
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_format>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
lea    0xf18(%rip),%r15
mov    $0x1,%edi
mov    %r15,%rsi
call   1050 <lua_check_string@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1070 <luaI_addchar@plt>
mov    $0x2,%r12d
lea    0x51(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%al
cmp    $0x25,%al
je     1200 <str_format+0x60>
test   %al,%al
je     13e7 <str_format+0x247>
add    $0x1,%rbx
movsbl %al,%edi
call   1070 <luaI_addchar@plt>
jmp    11e0 <str_format+0x40>
nopl   0x0(%rax)
mov    0x1(%rbx),%r14b
cmp    $0x25,%r14b
jne    121a <str_format+0x7a>
add    $0x2,%rbx
mov    $0x25,%edi
call   1070 <luaI_addchar@plt>
jmp    11e0 <str_format+0x40>
movb   $0x25,0x10(%rsp)
mov    %r14b,0x11(%rsp)
movsbl %r14b,%edi
call   1090 <isalpha@plt>
test   %eax,%eax
mov    %r12,0x8(%rsp)
je     1245 <str_format+0xa5>
add    $0x2,%rbx
mov    $0x1,%r12d
jmp    12e7 <str_format+0x147>
xor    %r15d,%r15d
mov    $0x2,%r12d
jmp    126b <str_format+0xcb>
movzbl (%rbx,%r12,1),%r14d
mov    %r14b,0x10(%rsp,%r12,1)
movsbl %r14b,%edi
call   1090 <isalpha@plt>
add    $0x1,%r12
test   %eax,%eax
jne    12d4 <str_format+0x134>
lea    -0x1(%r12),%r13
movsbl %r14b,%ebp
mov    %ebp,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     12b0 <str_format+0x110>
lea    (%r15,%r15,4),%eax
lea    0x0(%rbp,%rax,2),%ecx
lea    -0x30(%rbp,%rax,2),%r15d
cmp    $0x800,%ecx
jl     12a1 <str_format+0x101>
lea    0xe3b(%rip),%rdi
call   10a0 <lua_error@plt>
cmp    $0x31,%r13
jb     1250 <str_format+0xb0>
jmp    12c3 <str_format+0x123>
nopl   0x0(%rax)
cmp    $0x2e,%r14b
mov    $0x0,%eax
cmove  %eax,%r15d
cmp    $0x31,%r13
jb     1250 <str_format+0xb0>
lea    0xe41(%rip),%rdi
call   10a0 <lua_error@plt>
jmp    1250 <str_format+0xb0>
add    %r12,%rbx
add    $0xffffffffffffffff,%r12
lea    0xdee(%rip),%r15
lea    0x51(%rsp),%r13
add    $0x1,%r12d
movb   $0x0,0x10(%rsp,%r12,1)
movsbl %r14b,%eax
add    $0xffffffbb,%eax
cmp    $0x33,%eax
lea    0xcfe(%rip),%rcx
ja     1369 <str_format+0x1c9>
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%rdi
lea    0x1(%rdi),%ebp
mov    %r15,%rsi
call   1030 <lua_check_number@plt>
lea    0x50(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %ebp,%r12d
mov    0x50(%rsp),%al
test   %al,%al
je     11e0 <str_format+0x40>
mov    %r13,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1070 <luaI_addchar@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1350 <str_format+0x1b0>
jmp    11e0 <str_format+0x40>
lea    0xde9(%rip),%rdi
call   10a0 <lua_error@plt>
mov    0x8(%rsp),%r12
jmp    1333 <str_format+0x193>
mov    0x8(%rsp),%r12
mov    %r12d,%edi
mov    %r15,%rsi
call   1050 <lua_check_string@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x7d0,%eax
jl     13aa <str_format+0x20a>
lea    0xd86(%rip),%rdi
call   10a0 <lua_error@plt>
add    $0x1,%r12d
lea    0x50(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
jmp    1333 <str_format+0x193>
mov    0x8(%rsp),%rdi
lea    0x1(%rdi),%ebp
mov    %r15,%rsi
call   1050 <lua_check_string@plt>
mov    %rax,%rdi
call   1080 <luaI_addquoted@plt>
mov    %ebp,%r12d
jmp    11e0 <str_format+0x40>
xor    %edi,%edi
call   1070 <luaI_addchar@plt>
mov    %eax,%edi
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <lua_pushstring@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"format\00"
@.str.1 = [52 x i8] c"format size/precision too long in function `format'\00"
@.str.2 = [32 x i8] c"bad format in function `format'\00"
@.str.3 = [46 x i8] c"string argument too long in function `format'\00"
@.str.4 = [43 x i8] c"invalid format option in function `format'\00"
define void @str_format() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [50 x i8]
%4 = alloca [2000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 1, i32* %1
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
%10 = call i8* @lua_check_string(i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %2
%11 = call i32 @luaI_addchar(i8 signext 0)
br label %12
12: ; preds = %164, %0
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %165
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 37
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
%24 = load i8, i8* %22
%25 = call i32 @luaI_addchar(i8 signext %24)
br label %164
26: ; preds = %16
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 37
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %2
%35 = load i8, i8* %33
%36 = call i32 @luaI_addchar(i8 signext %35)
br label %163
37: ; preds = %26
store i32 0, i32* %5
store i32 0, i32* %6
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %40
store i8 37, i8* %41
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %2
%44 = load i8, i8* %42
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %46
store i8 %44, i8* %47
br label %48
48: ; preds = %93, %37
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = call i32 @isalpha(i8 signext %52)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
br i1 %55, label %56, label %100
56: ; preds = %48
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = call i64 @isdigit(i8 signext %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %78
63: ; preds = %56
%64 = load i32, i32* %5
%65 = mul nsw i32 %64, 10
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = add nsw i32 %65, %70
%72 = sub nsw i32 %71, 48
store i32 %72, i32* %5
%73 = load i32, i32* %5
%74 = icmp sge i32 %73, 2000
br i1 %74, label %75, label %77
75: ; preds = %63
%76 = call i32 @lua_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %77
77: ; preds = %75, %63
br label %87
78: ; preds = %56
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 46
br i1 %84, label %85, label %86
85: ; preds = %78
store i32 0, i32* %5
br label %86
86: ; preds = %85, %78
br label %87
87: ; preds = %86, %77
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
store i32 %89, i32* %6
%90 = icmp sge i32 %89, 50
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %93
93: ; preds = %91, %87
%94 = load i8*, i8** %2
%95 = getelementptr inbounds i8, i8* %94, i32 1
store i8* %95, i8** %2
%96 = load i8, i8* %94
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %98
store i8 %96, i8* %99
br label %48
100: ; preds = %48
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %103
store i8 0, i8* %104
%105 = load i32, i32* %6
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %106
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
switch i32 %109, label %144 [
i32 113, label %110
i32 115, label %116
i32 99, label %130
i32 100, label %130
i32 105, label %130
i32 111, label %130
i32 117, label %130
i32 120, label %130
i32 88, label %130
i32 101, label %137
i32 69, label %137
i32 102, label %137
i32 103, label %137
]
110: ; preds = %100
%111 = load i32, i32* %1
%112 = add nsw i32 %111, 1
store i32 %112, i32* %1
%113 = call i8* @lua_check_string(i32 %111, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%114 = call i32 @luaI_addquoted(i8* %113)
%115 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
store i8 0, i8* %115
br label %146
116: ; preds = %100
%117 = load i32, i32* %1
%118 = add nsw i32 %117, 1
store i32 %118, i32* %1
%119 = call i8* @lua_check_string(i32 %117, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %119, i8** %7
%120 = load i8*, i8** %7
%121 = call i32 @strlen(i8* %120)
%122 = icmp sge i32 %121, 2000
br i1 %122, label %123, label %125
123: ; preds = %116
%124 = call i32 @lua_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
br label %125
125: ; preds = %123, %116
%126 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%127 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%128 = load i8*, i8** %7
%129 = call i32 (i8*, i8*, ...) @sprintf(i8* %126, i8* %127, i8* %128)
br label %146
130: ; preds = %100, %100, %100, %100, %100, %100, %100
%131 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%132 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%133 = load i32, i32* %1
%134 = add nsw i32 %133, 1
store i32 %134, i32* %1
%135 = call i32 @lua_check_number(i32 %133, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%136 = call i32 (i8*, i8*, ...) @sprintf(i8* %131, i8* %132, i32 %135)
br label %146
137: ; preds = %100, %100, %100, %100
%138 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%139 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%140 = load i32, i32* %1
%141 = add nsw i32 %140, 1
store i32 %141, i32* %1
%142 = call i32 @lua_check_number(i32 %140, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%143 = call i32 (i8*, i8*, ...) @sprintf(i8* %138, i8* %139, i32 %142)
br label %146
144: ; preds = %100
%145 = call i32 @lua_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %146
146: ; preds = %144, %137, %130, %125, %110
store i32 0, i32* %6
br label %147
147: ; preds = %159, %146
%148 = load i32, i32* %6
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 %149
%151 = load i8, i8* %150
%152 = icmp ne i8 %151, 0
br i1 %152, label %153, label %162
153: ; preds = %147
%154 = load i32, i32* %6
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 %155
%157 = load i8, i8* %156
%158 = call i32 @luaI_addchar(i8 signext %157)
br label %159
159: ; preds = %153
%160 = load i32, i32* %6
%161 = add nsw i32 %160, 1
store i32 %161, i32* %6
br label %147
162: ; preds = %147
br label %163
163: ; preds = %162, %32
br label %164
164: ; preds = %163, %21
br label %12
165: ; preds = %12
%166 = call i32 @luaI_addchar(i8 signext 0)
%167 = call i32 @lua_pushstring(i32 %166)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"format\00"
@.str.1 = [52 x i8] c"format size/precision too long in function `format'\00"
@.str.2 = [32 x i8] c"bad format in function `format'\00"
@.str.3 = [46 x i8] c"string argument too long in function `format'\00"
@.str.4 = [43 x i8] c"invalid format option in function `format'\00"
define void @str_format() {
%1 = alloca [50 x i8]
%2 = alloca [2000 x i8]
%3 = tail call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @luaI_addchar(i8 signext 0)
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 1
br label %8
8: ; preds = %103, %0
%9 = phi i8* [ %61, %103 ], [ %3, %0 ]
%10 = phi i32 [ %104, %103 ], [ 2, %0 ]
br label %11
11: ; preds = %24, %8
%12 = phi i8* [ %9, %8 ], [ %25, %24 ]
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 0, label %105
i8 37, label %17
]
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = tail call i32 @luaI_addchar(i8 signext %13)
br label %24
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 37
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %12, i64 2
%23 = tail call i32 @luaI_addchar(i8 signext 37)
br label %24
24: ; preds = %21, %14
%25 = phi i8* [ %15, %14 ], [ %22, %21 ]
br label %11
26: ; preds = %17
store i8 37, i8* %5
%27 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %19, i8* %7
%28 = tail call i32 @isalpha(i8 signext %19)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %60
30: ; preds = %26, %54
%31 = phi i64 [ %50, %54 ], [ 1, %26 ]
%32 = phi i8 [ %56, %54 ], [ %19, %26 ]
%33 = phi i32 [ %49, %54 ], [ 0, %26 ]
%34 = phi i8* [ %55, %54 ], [ %27, %26 ]
%35 = tail call i64 @isdigit(i8 signext %32)
%36 = icmp eq i64 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %30
%38 = mul nsw i32 %33, 10
%39 = sext i8 %32 to i32
%40 = add nsw i32 %38, %39
%41 = add nsw i32 %40, -48
%42 = icmp sgt i32 %40, 2047
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = tail call i32 @lua_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %48
45: ; preds = %30
%46 = icmp eq i8 %32, 46
%47 = select i1 %46, i32 0, i32 %33
br label %48
48: ; preds = %45, %37, %43
%49 = phi i32 [ %41, %43 ], [ %41, %37 ], [ %47, %45 ]
%50 = add nuw i64 %31, 1
%51 = icmp ugt i64 %31, 48
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = tail call i32 @lua_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = getelementptr inbounds i8, i8* %34, i64 1
%56 = load i8, i8* %34
%57 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %50
store i8 %56, i8* %57
%58 = tail call i32 @isalpha(i8 signext %56)
%59 = icmp eq i32 %58, 0
br i1 %59, label %30, label %60
60: ; preds = %54, %26
%61 = phi i8* [ %27, %26 ], [ %55, %54 ]
%62 = phi i64 [ 1, %26 ], [ %50, %54 ]
%63 = phi i8 [ %19, %26 ], [ %56, %54 ]
%64 = add i64 %62, 1
%65 = and i64 %64, 4294967295
%66 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %65
store i8 0, i8* %66
%67 = sext i8 %63 to i32
switch i32 %67, label %89 [
i32 113, label %68
i32 115, label %72
i32 99, label %81
i32 100, label %81
i32 105, label %81
i32 111, label %81
i32 117, label %81
i32 120, label %81
i32 88, label %81
i32 101, label %85
i32 69, label %85
i32 102, label %85
i32 103, label %85
]
68: ; preds = %60
%69 = add nsw i32 %10, 1
%70 = tail call i8* @lua_check_string(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%71 = tail call i32 @luaI_addquoted(i8* %70)
br label %103
72: ; preds = %60
%73 = add nsw i32 %10, 1
%74 = tail call i8* @lua_check_string(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%75 = tail call i32 @strlen(i8* %74)
%76 = icmp sgt i32 %75, 1999
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = tail call i32 @lua_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
br label %79
79: ; preds = %77, %72
%80 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* %5, i8* %74)
br label %91
81: ; preds = %60, %60, %60, %60, %60, %60, %60
%82 = add nsw i32 %10, 1
%83 = tail call i32 @lua_check_number(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%84 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* %5, i32 %83)
br label %91
85: ; preds = %60, %60, %60, %60
%86 = add nsw i32 %10, 1
%87 = tail call i32 @lua_check_number(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%88 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* %5, i32 %87)
br label %91
89: ; preds = %60
%90 = tail call i32 @lua_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %91
91: ; preds = %89, %85, %81, %79
%92 = phi i32 [ %73, %79 ], [ %82, %81 ], [ %86, %85 ], [ %10, %89 ]
%93 = load i8, i8* %6
%94 = icmp eq i8 %93, 0
br i1 %94, label %103, label %95
95: ; preds = %91, %95
%96 = phi i64 [ %99, %95 ], [ 0, %91 ]
%97 = phi i8 [ %101, %95 ], [ %93, %91 ]
%98 = tail call i32 @luaI_addchar(i8 signext %97)
%99 = add nuw i64 %96, 1
%100 = getelementptr inbounds [2000 x i8], [2000 x i8]* %2, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = icmp eq i8 %101, 0
br i1 %102, label %103, label %95
103: ; preds = %95, %68, %91
%104 = phi i32 [ %69, %68 ], [ %92, %91 ], [ %92, %95 ]
br label %8
105: ; preds = %11
%106 = tail call i32 @luaI_addchar(i8 signext 0)
%107 = tail call i32 @lua_pushstring(i32 %106)
ret void
}