#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 getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
long syscall(int, long);
void test_selfDefined_systemCall(int argc, char **argv) {
  printf(
      "test_selfDefined_systemCall; -enter; process_name=%s, process_id=%d\n",
      argv[0], getpid());
  long ret = 0;
  long param1 = 57;
  printf("before call self defined system call#%d\n", 329);
  ret = syscall(329, param1);
  printf("after call self defined system call#%d, ret=%ld\n", 329, ret);
  printf("test_selfDefined_systemCall; sleep 30s before exit\n");
  sleep(30);
  printf("test_selfDefined_systemCall; -exit\n");
}


x86 assembly (clang, -O0):
<test_selfDefined_systemCall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x39,-0x20(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x149,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    $0x149,%edi
call   1050 <syscall@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    0xeb9(%rip),%rdi
mov    $0x149,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1e,%edi
call   1060 <sleep@plt>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_selfDefined_systemCall>:
push   %rbx
mov    (%rsi),%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed0(%rip),%rdi
mov    $0x149,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x39,%esi
mov    $0x149,%edi
call   1060 <syscall@plt>
lea    0xed7(%rip),%rdi
mov    $0x149,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1e,%edi
call   1070 <sleep@plt>
lea    0xf0f(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"test_selfDefined_systemCall; -enter; process_name=%s, process_id=%d\0A\00"
@.str.1 = [41 x i8] c"before call self defined system call#%d\0A\00"
@.str.2 = [49 x i8] c"after call self defined system call#%d, ret=%ld\0A\00"
@.str.3 = [52 x i8] c"test_selfDefined_systemCall; sleep 30s before exit\0A\00"
@.str.4 = [36 x i8] c"test_selfDefined_systemCall; -exit\0A\00"
define void @test_selfDefined_systemCall(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %4
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i32 (...) @getpid()
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
store i64 0, i64* %5
store i64 57, i64* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 329)
%13 = load i64, i64* %6
%14 = call i64 @syscall(i32 329, i64 %13)
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 329, i64 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @sleep(i32 30)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [69 x i8] c"test_selfDefined_systemCall; -enter; process_name=%s, process_id=%d\0A\00"
@.str.1 = [41 x i8] c"before call self defined system call#%d\0A\00"
@.str.2 = [49 x i8] c"after call self defined system call#%d, ret=%ld\0A\00"
@str = [51 x i8] c"test_selfDefined_systemCall; sleep 30s before exit\00"
@str.5 = [35 x i8] c"test_selfDefined_systemCall; -exit\00"
define void @test_selfDefined_systemCall(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 329)
%7 = tail call i64 @syscall(i32 329, i64 57)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 329, i64 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @sleep(i32 30)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
ret void
}