#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*/ O_WRONLY;
int /*<<< orphan*/ asprintf(char **, char *, char *);
int dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *get_update_query(double, int /*<<< orphan*/, int /*<<< orphan*/,
                       int /*<<< orphan*/, double, double);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pg_db_reset(char *db_name, int dump) {
  char *update_query, *gquery;
  gquery = get_update_query(0.5, 0, 0, 0, 1.0 / 13.0, 0.088);
  if (!gquery)
    return 1;
  asprintf(&update_query, "%s", gquery);
  free(gquery);
  if (dump) {
    int fd = open("/dev/null", O_WRONLY);
    if (dup2(fd, 1) == -1) {
      perror("dup2");
      return 1;
    }
  }
  execlp("psql", "psql", "-c", update_query, db_name, NULL);
  perror("exec");
  return 1;
}


x86 assembly (clang, -O0):
<pg_db_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  0xe79(%rip),%xmm0
xor    %edx,%edx
movsd  0xe77(%rip),%xmm1
movsd  0xe77(%rip),%xmm2
mov    %edx,%edi
mov    %edx,%esi
call   1090 <get_update_query@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bd <pg_db_reset+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    1265 <pg_db_reset+0xf5>
mov    -0x28(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x14(%rbp)
je     122f <pg_db_reset+0xbf>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe27(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    122a <pg_db_reset+0xba>
lea    0xe0c(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1265 <pg_db_reset+0xf5>
jmp    122f <pg_db_reset+0xbf>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xdec(%rip),%rsi
lea    0xdea(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1080 <execlp@plt>
lea    0xdd9(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pg_db_reset>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
movsd  0xe7b(%rip),%xmm0
movsd  0xe7b(%rip),%xmm1
movsd  0xe7b(%rip),%xmm2
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <get_update_query@plt>
test   %rax,%rax
jne    11b3 <pg_db_reset+0x43>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rax,%rbx
lea    0xe5b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rax,%rdx
call   1050 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1205 <pg_db_reset+0x95>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1205 <pg_db_reset+0x95>
lea    0xe22(%rip),%rdi
jmp    122d <pg_db_reset+0xbd>
mov    0x8(%rsp),%rcx
lea    0xe19(%rip),%rdi
lea    0xe17(%rip),%rdx
mov    %rdi,%rsi
mov    %r14,%r8
xor    %r9d,%r9d
call   1080 <execlp@plt>
lea    0xe05(%rip),%rdi
call   1070 <perror@plt>
jmp    11a5 <pg_db_reset+0x35>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"dup2\00"
@.str.3 = [5 x i8] c"psql\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [5 x i8] c"exec\00"
define i32 @pg_db_reset(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i8* @get_update_query(double 5.000000e-01, i32 0, i32 0, i32 0, double 0x3FB3B13B13B13B14, double 0x3FB6872B020C49BA)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 1, i32* %3
br label %34
13: ; preds = %2
%14 = load i8*, i8** %7
%15 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %7
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %13
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = call i32 @dup2(i32 %23, i32 1)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %34
28: ; preds = %20
br label %29
29: ; preds = %28, %13
%30 = load i8*, i8** %6
%31 = load i8*, i8** %4
%32 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* %31, i32* null)
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %34
34: ; preds = %29, %26, %12
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"dup2\00"
@.str.3 = [5 x i8] c"psql\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [5 x i8] c"exec\00"
define i32 @pg_db_reset(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @get_update_query(double 5.000000e-01, i32 0, i32 0, i32 0, double 0x3FB3B13B13B13B14, double 0x3FB6872B020C49BA)
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%9 = call i32 @free(i8* %5)
%10 = icmp eq i32 %1, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @dup2(i32 %13, i32 1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %19, label %16
16: ; preds = %11, %7
%17 = load i8*, i8** %3
%18 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %17, i8* %0, i32* null)
br label %19
19: ; preds = %11, %16
%20 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %11 ]
%21 = call i32 @perror(i8* %20)
br label %22
22: ; preds = %19, %2
ret i32 1
}