#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*/ SG_DB_Close(void *);
void *SG_DB_Open(int /*<<< orphan*/ *);
int SG_DB_Set(void *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  void *sgdb;
  int ret = 0;
  printf("rg_conf_set v%s\n", "0.1");
  printf("Copyright (C) 2014  Triple Oxygen <oxy@g3n.org>\n\n");
  if (argc != 3) {
    usage(argv[0]);
    return -1;
  }
  sgdb = SG_DB_Open(NULL);
  if (!sgdb) {
    printf("[-] Failed to open SG DB.");
    return -1;
  }
  ret = SG_DB_Set(sgdb, argv[1], argv[2]);
  printf("[+] Ret code: %d\n", ret);
  SG_DB_Close(sgdb);
  printf("[+] Done.\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11b2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <main+0xdf>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <SG_DB_Open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x94>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
call   1050 <SG_DB_Set@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <SG_DB_Close@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe8d(%rip),%rdi
lea    0xe97(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%ebp
jne    11da <main+0x7a>
xor    %r14d,%r14d
xor    %edi,%edi
call   1070 <SG_DB_Open@plt>
test   %rax,%rax
je     11e4 <main+0x84>
mov    %rax,%r15
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
mov    %rax,%rdi
call   1060 <SG_DB_Set@plt>
lea    0xe74(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1080 <SG_DB_Close@plt>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
jmp    11f8 <main+0x98>
mov    (%rbx),%rdi
call   1050 <usage@plt>
jmp    11f2 <main+0x92>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"rg_conf_set v%s\0A\00"
@.str.1 = [4 x i8] c"0.1\00"
@.str.2 = [50 x i8] c"Copyright (C) 2014 Triple Oxygen <oxy@g3n.org>\0A\0A\00"
@.str.3 = [26 x i8] c"[-] Failed to open SG DB.\00"
@.str.4 = [18 x i8] c"[+] Ret code: %d\0A\00"
@.str.5 = [12 x i8] c"[+] Done.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 -1, i32* %3
br label %37
17: ; preds = %2
%18 = call i8* @SG_DB_Open(i32* null)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @SG_DB_Set(i8* %24, i8* %27, i8* %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %6
%35 = call i32 @SG_DB_Close(i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %37
37: ; preds = %23, %21, %12
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [17 x i8] c"rg_conf_set v%s\0A\00"
@.str.1 = [4 x i8] c"0.1\00"
@.str.3 = [26 x i8] c"[-] Failed to open SG DB.\00"
@.str.4 = [18 x i8] c"[+] Ret code: %d\0A\00"
@str = [49 x i8] c"Copyright (C) 2014 Triple Oxygen <oxy@g3n.org>\0A\00"
@str.6 = [11 x i8] c"[+] Done.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %23
9: ; preds = %2
%10 = tail call i8* @SG_DB_Open(i32* null)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %23
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @SG_DB_Set(i8* %10, i8* %16, i8* %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = tail call i32 @SG_DB_Close(i8* %10)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %23
23: ; preds = %14, %12, %6
%24 = phi i32 [ -1, %6 ], [ 0, %14 ], [ -1, %12 ]
ret i32 %24
}