#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 atoi(char *);
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, void *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  const char *buf = "--testfcntl写入的数据--\n";
  fd = atoi(argv[1]);
  printf("\t\t\t*******************\n");
  printf("子进程：pid=%d, fd=%d, 调用testfcntl执行文件:\n", getpid(), fd);
  write(fd, (void *)buf, strlen(buf));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe55(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"--testfcntl\E5\86\99\E5\85\A5\E7\9A\84\E6\95\B0\E6\8D\AE--\0A\00"
@.str.1 = [24 x i8] c"\09\09\09*******************\0A\00"
@.str.2 = [57 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8B\EF\BC\9Apid=%d, fd=%d, \E8\B0\83\E7\94\A8testfcntl\E6\89\A7\E8\A1\8C\E6\96\87\E4\BB\B6:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @atoi(i8* %10)
store i32 %11, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (...) @getpid()
%14 = load i32, i32* %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %6
%17 = load i8*, i8** %7
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"--testfcntl\E5\86\99\E5\85\A5\E7\9A\84\E6\95\B0\E6\8D\AE--\0A\00"
@.str.2 = [57 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8B\EF\BC\9Apid=%d, fd=%d, \E8\B0\83\E7\94\A8testfcntl\E6\89\A7\E8\A1\8C\E6\96\87\E4\BB\B6:\0A\00"
@str = [23 x i8] c"\09\09\09*******************\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %5)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @close(i32 %5)
ret i32 0
}