#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*/ printf(char *, ...);
int sysapi_create_lockfile(char *);
int sysapi_file_exist(char *);
int sysapi_get_arch();
int sysapi_get_rand();
int sysapi_get_rand_range(int);
int /*<<< orphan*/ sysapi_printf(int, char *, ...);
int test_get_line();
int test_getdelim();
int main(void) {
  int a = 1, b = 2;
  int failure = 0;
  int ret;
  sysapi_printf(3, "test"
                   " "
                   "This is an info msg\n");
  sysapi_printf(2, "test: "
                   " "
                   "This is a warning msg\n");
  sysapi_printf(1, "test: "
                   " "
                   "This is an err msg\n");
  sysapi_printf(3,
                "testing"
                " "
                "%d %d\n",
                a, b);
  sysapi_printf(4,
                "testing"
                " "
                "%d %d\n",
                a, b);
  printf("%s\n", (sysapi_get_arch() == 1) ? "64" : "32");
  printf("%d\n", sysapi_get_rand());
  printf("%d\n", sysapi_get_rand_range(22));
  ret = test_get_line();
  if (ret < 0) {
    printf("get line test failure\n");
    failure++;
  }
  ret = test_getdelim();
  if (ret < 0) {
    printf("get delimiter test failure\n");
    failure++;
  }
  ret = sysapi_create_lockfile("/tmp/sysapi_test_lock.lock");
  if (ret == 0) {
    ret = sysapi_file_exist("/tmp/sysapi_test_lock.lock");
    if (ret != 0)
      failure++;
  }
  return failure;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x3,%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <sysapi_printf@plt>
mov    $0x2,%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <sysapi_printf@plt>
mov    $0x1,%edi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1030 <sysapi_printf@plt>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x3,%edi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1030 <sysapi_printf@plt>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x4,%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <sysapi_printf@plt>
mov    $0x0,%al
call   1090 <sysapi_get_arch@plt>
mov    %eax,%ecx
lea    0xe3a(%rip),%rsi
lea    0xe30(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <sysapi_get_rand@plt>
mov    %eax,%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x16,%edi
call   1070 <sysapi_get_rand_range@plt>
mov    %eax,%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <test_get_line@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a7 <main+0x117>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <test_getdelim@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d2 <main+0x142>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xdc6(%rip),%rdi
call   10a0 <sysapi_create_lockfile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1312 <main+0x182>
lea    0xdad(%rip),%rdi
call   1050 <sysapi_file_exist@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     130d <main+0x17d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1312 <main+0x182>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe56(%rip),%rsi
xor    %ebp,%ebp
mov    $0x3,%edi
xor    %eax,%eax
call   1030 <sysapi_printf@plt>
lea    0xe5b(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <sysapi_printf@plt>
lea    0xe66(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <sysapi_printf@plt>
lea    0xe6e(%rip),%rbx
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <sysapi_printf@plt>
mov    $0x4,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <sysapi_printf@plt>
xor    %eax,%eax
call   10a0 <sysapi_get_arch@plt>
cmp    $0x1,%eax
lea    0xe3a(%rip),%rax
lea    0xe36(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <sysapi_get_rand@plt>
lea    0xe18(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x16,%edi
call   1080 <sysapi_get_rand_range@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <test_get_line@plt>
test   %eax,%eax
jns    1284 <main+0xe4>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
xor    %eax,%eax
call   1050 <test_getdelim@plt>
test   %eax,%eax
jns    129e <main+0xfe>
lea    0xded(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%ebp
lea    0xdc3(%rip),%rdi
call   10b0 <sysapi_create_lockfile@plt>
test   %eax,%eax
jne    12c0 <main+0x120>
lea    0xdb3(%rip),%rdi
call   1060 <sysapi_file_exist@plt>
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"test This is an info msg\0A\00"
@.str.1 = [30 x i8] c"test: This is a warning msg\0A\00"
@.str.2 = [27 x i8] c"test: This is an err msg\0A\00"
@.str.3 = [15 x i8] c"testing %d %d\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [3 x i8] c"64\00"
@.str.6 = [3 x i8] c"32\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [23 x i8] c"get line test failure\0A\00"
@.str.9 = [28 x i8] c"get delimiter test failure\0A\00"
@.str.10 = [27 x i8] c"/tmp/sysapi_test_lock.lock\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 2, i32* %3
store i32 0, i32* %4
%6 = call i32 (i32, i8*, ...) @sysapi_printf(i32 3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i32, i8*, ...) @sysapi_printf(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i32, i8*, ...) @sysapi_printf(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 (i32, i8*, ...) @sysapi_printf(i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 (i32, i8*, ...) @sysapi_printf(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 (...) @sysapi_get_arch()
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = call i32 (...) @sysapi_get_rand()
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %20)
%22 = call i32 @sysapi_get_rand_range(i32 22)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @test_get_line()
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %27, %0
%32 = call i32 (...) @test_getdelim()
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %39
39: ; preds = %35, %31
%40 = call i32 @sysapi_create_lockfile(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = call i32 @sysapi_file_exist(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %50
50: ; preds = %47, %43
br label %51
51: ; preds = %50, %39
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@.str = [26 x i8] c"test This is an info msg\0A\00"
@.str.1 = [30 x i8] c"test: This is a warning msg\0A\00"
@.str.2 = [27 x i8] c"test: This is an err msg\0A\00"
@.str.3 = [15 x i8] c"testing %d %d\0A\00"
@.str.5 = [3 x i8] c"64\00"
@.str.6 = [3 x i8] c"32\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.10 = [27 x i8] c"/tmp/sysapi_test_lock.lock\00"
@str = [27 x i8] c"get delimiter test failure\00"
@str.11 = [22 x i8] c"get line test failure\00"
define i32 @main() {
%1 = tail call i32 (i32, i8*, ...) @sysapi_printf(i32 3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i32, i8*, ...) @sysapi_printf(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (i32, i8*, ...) @sysapi_printf(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 (i32, i8*, ...) @sysapi_printf(i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 2)
%5 = tail call i32 (i32, i8*, ...) @sysapi_printf(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 2)
%6 = tail call i32 (...) @sysapi_get_arch()
%7 = icmp eq i32 %6, 1
%8 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
%10 = tail call i32 (...) @sysapi_get_rand()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %10)
%12 = tail call i32 @sysapi_get_rand_range(i32 22)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @test_get_line()
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.11, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = phi i32 [ 1, %16 ], [ 0, %0 ]
%20 = tail call i32 (...) @test_getdelim()
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%24 = add nuw nsw i32 %19, 1
br label %25
25: ; preds = %22, %18
%26 = phi i32 [ %24, %22 ], [ %19, %18 ]
%27 = tail call i32 @sysapi_create_lockfile(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = tail call i32 @sysapi_file_exist(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %26, %32
br label %34
34: ; preds = %29, %25
%35 = phi i32 [ %26, %25 ], [ %33, %29 ]
ret i32 %35
}