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

/* Variables and functions */
int /*<<< orphan*/ TSDB_insert(struct TSDB_metric_t *, int, int, int);
struct TSDB_metric_t *TSDB_open(char *);
void *atoi(int /*<<< orphan*/);
int getopt(int, char *const *, char *);
int insert_usage();
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
int insert_main(int argc, char *const *argv) {
  int o, value, column;
  time_t insert_time;
  char *filename = 0;
  column = insert_time = value = 0;
  while ((o = getopt(argc, argv, "f:t:v:c:h")) != -1) {
    switch (o) {
    case 'c':
      column = atoi(optarg);
      break;
    case 'f':
      filename = malloc(strlen(optarg) + 1);
      memcpy(filename, optarg, strlen(optarg) + 1);
      break;
    case 't':
      insert_time = atoi(optarg);
      break;
    case 'v':
      value = atoi(optarg);
    }
  }
  if (!filename || !value) {
    return insert_usage();
  }
  struct TSDB_metric_t *metric = TSDB_open(filename);
  TSDB_insert(metric, column, insert_time, value);
  return 0;
}


x86 assembly (clang, -O0):
<insert_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     128a <insert_main+0x10a>
mov    -0x14(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x13,%eax
ja     1285 <insert_main+0x105>
mov    -0x38(%rbp),%rax
lea    0xe15(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1285 <insert_main+0x105>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
jmp    1285 <insert_main+0x105>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1285 <insert_main+0x105>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11ac <insert_main+0x2c>
cmpq   $0x0,-0x28(%rbp)
je     129f <insert_main+0x11f>
cmpl   $0x0,-0x18(%rbp)
jne    12ae <insert_main+0x12e>
mov    $0x0,%al
call   1060 <insert_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12d4 <insert_main+0x154>
mov    -0x28(%rbp),%rdi
call   1070 <TSDB_open@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <TSDB_insert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0xeb0(%rip),%r13
lea    0xe59(%rip),%r12
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
jmp    11c9 <insert_main+0x49>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     125d <insert_main+0xdd>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
lea    -0x63(%rax),%ecx
cmp    $0x13,%ecx
ja     11c0 <insert_main+0x40>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %rax,0x8(%rsp)
jmp    11c9 <insert_main+0x49>
mov    0x2df5(%rip),%r15
mov    (%r15),%edi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    (%r15),%r15d
mov    %r15d,%edi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <memcpy@plt>
jmp    11c9 <insert_main+0x49>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %rax,0x10(%rsp)
jmp    11c9 <insert_main+0x49>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %rax,(%rsp)
jmp    11c9 <insert_main+0x49>
test   %r14,%r14
je     1297 <insert_main+0x117>
cmpl   $0x0,(%rsp)
je     1297 <insert_main+0x117>
mov    %r14,%rdi
call   1070 <TSDB_open@plt>
mov    %rax,%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    (%rsp),%rcx
call   1030 <TSDB_insert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <insert_usage@plt>

LLVM IR (-O0):
%struct.TSDB_metric_t = type { i32 }
@.str = [10 x i8] c"f:t:v:c:h\00"
@optarg = global i32 0
define i32 @insert_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.TSDB_metric_t*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i32 0, i32* %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %12
12: ; preds = %42, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %43
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %42 [
i32 99, label %19
i32 102, label %23
i32 116, label %34
i32 118, label %38
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = call i8* @atoi(i32 %20)
%22 = ptrtoint i8* %21 to i32
store i32 %22, i32* %8
br label %42
23: ; preds = %17
%24 = load i32, i32* @optarg
%25 = call i32 @strlen(i32 %24)
%26 = add nsw i32 %25, 1
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = load i32, i32* @optarg
%30 = load i32, i32* @optarg
%31 = call i32 @strlen(i32 %30)
%32 = add nsw i32 %31, 1
%33 = call i32 @memcpy(i8* %28, i32 %29, i32 %32)
br label %42
34: ; preds = %17
%35 = load i32, i32* @optarg
%36 = call i8* @atoi(i32 %35)
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %9
br label %42
38: ; preds = %17
%39 = load i32, i32* @optarg
%40 = call i8* @atoi(i32 %39)
%41 = ptrtoint i8* %40 to i32
store i32 %41, i32* %7
br label %42
42: ; preds = %38, %17, %34, %23, %19
br label %12
43: ; preds = %12
%44 = load i8*, i8** %10
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %46, %43
%50 = call i32 (...) @insert_usage()
store i32 %50, i32* %3
br label %59
51: ; preds = %46
%52 = load i8*, i8** %10
%53 = call %struct.TSDB_metric_t* @TSDB_open(i8* %52)
store %struct.TSDB_metric_t* %53, %struct.TSDB_metric_t** %11
%54 = load %struct.TSDB_metric_t*, %struct.TSDB_metric_t** %11
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = load i32, i32* %7
%58 = call i32 @TSDB_insert(%struct.TSDB_metric_t* %54, i32 %55, i32 %56, i32 %57)
store i32 0, i32* %3
br label %59
59: ; preds = %51, %49
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.TSDB_metric_t = type { i32 }
@.str = [10 x i8] c"f:t:v:c:h\00"
@optarg = global i32 0
define i32 @insert_main(i32 %0, i8** %1) {
br label %3
3: ; preds = %38, %2
%4 = phi i32 [ %42, %38 ], [ 0, %2 ]
%5 = phi i32 [ %9, %38 ], [ 0, %2 ]
%6 = phi i32 [ %13, %38 ], [ 0, %2 ]
%7 = phi i8* [ %16, %38 ], [ null, %2 ]
br label %8
8: ; preds = %3, %19
%9 = phi i32 [ %5, %3 ], [ %23, %19 ]
%10 = phi i32 [ %6, %3 ], [ %13, %19 ]
%11 = phi i8* [ %7, %3 ], [ %16, %19 ]
br label %12
12: ; preds = %8, %33
%13 = phi i32 [ %10, %8 ], [ %37, %33 ]
%14 = phi i8* [ %11, %8 ], [ %16, %33 ]
br label %15
15: ; preds = %12, %24
%16 = phi i8* [ %14, %12 ], [ %28, %24 ]
br label %17
17: ; preds = %15, %17
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %18, label %17 [
i32 -1, label %43
i32 99, label %19
i32 102, label %24
i32 116, label %33
i32 118, label %38
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = tail call i8* @atoi(i32 %20)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i32
br label %8
24: ; preds = %17
%25 = load i32, i32* @optarg
%26 = tail call i32 @strlen(i32 %25)
%27 = add nsw i32 %26, 1
%28 = tail call i8* @malloc(i32 %27)
%29 = load i32, i32* @optarg
%30 = tail call i32 @strlen(i32 %29)
%31 = add nsw i32 %30, 1
%32 = tail call i32 @memcpy(i8* %28, i32 %29, i32 %31)
br label %15
33: ; preds = %17
%34 = load i32, i32* @optarg
%35 = tail call i8* @atoi(i32 %34)
%36 = ptrtoint i8* %35 to i64
%37 = trunc i64 %36 to i32
br label %12
38: ; preds = %17
%39 = load i32, i32* @optarg
%40 = tail call i8* @atoi(i32 %39)
%41 = ptrtoint i8* %40 to i64
%42 = trunc i64 %41 to i32
br label %3
43: ; preds = %17
%44 = icmp ne i8* %16, null
%45 = icmp ne i32 %4, 0
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = tail call i32 (...) @insert_usage()
br label %52
49: ; preds = %43
%50 = tail call %struct.TSDB_metric_t* @TSDB_open(i8* %16)
%51 = tail call i32 @TSDB_insert(%struct.TSDB_metric_t* %50, i32 %9, i32 %13, i32 %4)
br label %52
52: ; preds = %49, %47
%53 = phi i32 [ 0, %49 ], [ %48, %47 ]
ret i32 %53
}