#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 */
scalar_t__ piece(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int remove_duplicate_rows(char *tablename, char *primary_key_list) {
  char piece_buffer[128];
  int i;
  printf(" delete from %s ttt\n where rowid <> ( select max( rowid )\n 	"
         "	 from %s\n 		 where 1 = 1\n",
         tablename, tablename);
  for (i = 0; piece(piece_buffer, ',', primary_key_list, i); i++) {
    printf(" 		   and %s.%s = ttt.%s\n", tablename, piece_buffer,
           piece_buffer);
  }
  printf(" 		);\n");
  return 1;
}


x86 assembly (clang, -O0):
<remove_duplicate_rows>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x94(%rbp),%ecx
mov    $0x2c,%esi
call   1040 <piece@plt>
cmp    $0x0,%rax
je     11ac <remove_duplicate_rows+0x8c>
mov    -0x8(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1153 <remove_duplicate_rows+0x33>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_duplicate_rows>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xeb4(%rip),%rdi
mov    %r12,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x2c,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <piece@plt>
test   %rax,%rax
je     11ad <remove_duplicate_rows+0x7d>
mov    $0x1,%ebp
lea    0xedb(%rip),%r15
mov    %rsp,%rbx
nop
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <piece@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1180 <remove_duplicate_rows+0x50>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [87 x i8] c" delete from %s ttt\0A where rowid <> ( select max( rowid )\0A \09\09 from %s\0A \09\09 where 1 = 1\0A\00"
@.str.1 = [26 x i8] c" \09\09 and %s.%s = ttt.%s\0A\00"
@.str.2 = [7 x i8] c" \09\09);\0A\00"
define i32 @remove_duplicate_rows(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
store i32 0, i32* %6
br label %10
10: ; preds = %21, %2
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = call i64 @piece(i8* %11, i8 signext 44, i8* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %10
24: ; preds = %10
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [87 x i8] c" delete from %s ttt\0A where rowid <> ( select max( rowid )\0A \09\09 from %s\0A \09\09 where 1 = 1\0A\00"
@.str.1 = [26 x i8] c" \09\09 and %s.%s = ttt.%s\0A\00"
@str = [6 x i8] c" \09\09);\00"
define i32 @remove_duplicate_rows(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %0)
%6 = call i64 @piece(i8* %4, i8 signext 44, i8* %1, i32 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %4, i8* %4)
%11 = add nuw nsw i32 %9, 1
%12 = call i64 @piece(i8* %4, i8 signext 44, i8* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 1
}