#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 */
struct bmy_articles {
  int dummy;
};

/* Variables and functions */
char *bmy_algo_join_int_array_to_string(int const *, size_t, char);
struct bmy_articles *bmy_article_list_internal(char *);
char *calloc(size_t, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, size_t, size_t);
int strlen(char *);
struct bmy_articles *bmy_article_list_selected_boards_by_offset(
    const int boardnum_array[], size_t num, size_t limit, size_t offset) {
  char *sqlbuf = NULL, *s = NULL;
  size_t size = 0;
  struct bmy_articles *p = NULL;
  s = bmy_algo_join_int_array_to_string(boardnum_array, num, ',');
  if (s == NULL)
    goto END;
  size = strlen(s) + 512;
  sqlbuf = calloc(size, sizeof(char));
  if (sqlbuf == NULL)
    goto END;
  snprintf(
      sqlbuf, size,
      "SELECT `boardname_en`, `boardname_zh`, `timestamp`, `title`, `author`, "
      "`comments`, `accessed` from `t_boards`, `t_threads` WHERE "
      "`t_boards`.`boardnum` IN (%s) AND `t_boards`.`boardnum` = "
      "`t_threads`.`boardnum` ORDER BY `timestamp` desc LIMIT %zu OFFSET %zu",
      s, limit, offset);
  p = bmy_article_list_internal(sqlbuf);
END:
  if (s)
    free(s);
  if (sqlbuf)
    free(sqlbuf);
  return p;
}


x86 assembly (clang, -O0):
<bmy_article_list_selected_boards_by_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2c,%edx
call   1070 <bmy_algo_join_int_array_to_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11be <bmy_article_list_selected_boards_by_offset+0x5e>
jmp    1221 <bmy_article_list_selected_boards_by_offset+0xc1>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x200,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f4 <bmy_article_list_selected_boards_by_offset+0x94>
jmp    1221 <bmy_article_list_selected_boards_by_offset+0xc1>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xdf1(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <bmy_article_list_internal@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1235 <bmy_article_list_selected_boards_by_offset+0xd5>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1249 <bmy_article_list_selected_boards_by_offset+0xe9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmy_article_list_selected_boards_by_offset>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    $0x2c,%edx
call   1070 <bmy_algo_join_int_array_to_string@plt>
test   %rax,%rax
je     11d9 <bmy_article_list_selected_boards_by_offset+0x79>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
add    $0x200,%eax
movslq %eax,%r13
mov    %r13,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11de <bmy_article_list_selected_boards_by_offset+0x7e>
mov    %rax,%r12
lea    0xe53(%rip),%rdx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1080 <bmy_article_list_internal@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rbx
jmp    11e1 <bmy_article_list_selected_boards_by_offset+0x81>
xor    %r14d,%r14d
jmp    11e9 <bmy_article_list_selected_boards_by_offset+0x89>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bmy_articles = type { i32 }
@.str = [257 x i8] c"SELECT `boardname_en`, `boardname_zh`, `timestamp`, `title`, `author`, `comments`, `accessed` from `t_boards`, `t_threads` WHERE `t_boards`.`boardnum` IN (%s) AND `t_boards`.`boardnum` = `t_threads`.`boardnum` ORDER BY `timestamp` desc LIMIT %zu OFFSET %zu\00"
define %struct.bmy_articles* @bmy_article_list_selected_boards_by_offset(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.bmy_articles*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i8* null, i8** %9
store i8* null, i8** %10
store i64 0, i64* %11
store %struct.bmy_articles* null, %struct.bmy_articles** %12
%13 = load i32*, i32** %5
%14 = load i64, i64* %6
%15 = call i8* @bmy_algo_join_int_array_to_string(i32* %13, i64 %14, i8 signext 44)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %4
br label %38
19: ; preds = %4
%20 = load i8*, i8** %10
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 512
%23 = sext i32 %22 to i64
store i64 %23, i64* %11
%24 = load i64, i64* %11
%25 = call i8* @calloc(i64 %24, i32 1)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %19
br label %38
29: ; preds = %19
%30 = load i8*, i8** %9
%31 = load i64, i64* %11
%32 = load i8*, i8** %10
%33 = load i64, i64* %7
%34 = load i64, i64* %8
%35 = call i32 @snprintf(i8* %30, i64 %31, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @.str, i64 0, i64 0), i8* %32, i64 %33, i64 %34)
%36 = load i8*, i8** %9
%37 = call %struct.bmy_articles* @bmy_article_list_internal(i8* %36)
store %struct.bmy_articles* %37, %struct.bmy_articles** %12
br label %38
38: ; preds = %29, %28, %18
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %10
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %41, %38
%45 = load i8*, i8** %9
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %9
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %47, %44
%51 = load %struct.bmy_articles*, %struct.bmy_articles** %12
ret %struct.bmy_articles* %51
}

LLVM IR (-O2):
%struct.bmy_articles = type { i32 }
@.str = [257 x i8] c"SELECT `boardname_en`, `boardname_zh`, `timestamp`, `title`, `author`, `comments`, `accessed` from `t_boards`, `t_threads` WHERE `t_boards`.`boardnum` IN (%s) AND `t_boards`.`boardnum` = `t_threads`.`boardnum` ORDER BY `timestamp` desc LIMIT %zu OFFSET %zu\00"
define %struct.bmy_articles* @bmy_article_list_selected_boards_by_offset(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = tail call i8* @bmy_algo_join_int_array_to_string(i32* %0, i64 %1, i8 signext 44)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %5)
%9 = add nsw i32 %8, 512
%10 = sext i32 %9 to i64
%11 = tail call i8* @calloc(i64 %10, i32 1)
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @snprintf(i8* %11, i64 %10, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @.str, i64 0, i64 0), i8* %5, i64 %2, i64 %3)
%15 = tail call %struct.bmy_articles* @bmy_article_list_internal(i8* %11)
%16 = tail call i32 @free(i8* %5)
br label %17
17: ; preds = %7, %13
%18 = phi i8* [ %11, %13 ], [ %5, %7 ]
%19 = phi %struct.bmy_articles* [ %15, %13 ], [ null, %7 ]
%20 = tail call i32 @free(i8* %18)
br label %21
21: ; preds = %17, %4
%22 = phi %struct.bmy_articles* [ null, %4 ], [ %19, %17 ]
ret %struct.bmy_articles* %22
}