#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 */
struct utsname {
  char *nodename;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int sethostname(void *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(void *);
int uname(struct utsname *);
int childFunc(void *arg) {
  struct utsname uts;
  if (sethostname(arg, strlen(arg)) == -1)
    do {
      perror("sethostname");
      exit(EXIT_FAILURE);
    } while (0);
  if (uname(&uts) == -1)
    do {
      perror("uname");
      exit(EXIT_FAILURE);
    } while (0);
  printf("uts.nodename in child:  %s\n", uts.nodename);
  sleep(1000);
  return 0;
}


x86 assembly (clang, -O0):
<childFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1060 <sethostname@plt>
cmp    $0xffffffff,%eax
jne    11c0 <childFunc+0x50>
jmp    11a6 <childFunc+0x36>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
jne    11f1 <childFunc+0x81>
jmp    11d7 <childFunc+0x67>
lea    0xe2e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<childFunc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <sethostname@plt>
cmp    $0xffffffff,%eax
je     11be <childFunc+0x4e>
lea    0x8(%rsp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     11c7 <childFunc+0x57>
mov    0x8(%rsp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe3b(%rip),%rdi
jmp    11ce <childFunc+0x5e>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i8* }
@.str = [12 x i8] c"sethostname\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"uname\00"
@.str.2 = [28 x i8] c"uts.nodename in child: %s\0A\00"
define i32 @childFunc(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.utsname
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = call i32 @sethostname(i8* %4, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
br label %10
10: ; preds = %9
%11 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %1
%16 = call i32 @uname(%struct.utsname* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %15
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %15
%25 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @sleep(i32 1000)
ret i32 0
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@.str = [12 x i8] c"sethostname\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"uname\00"
@.str.2 = [28 x i8] c"uts.nodename in child: %s\0A\00"
define i32 @childFunc(i8* %0) {
%2 = alloca %struct.utsname
%3 = bitcast %struct.utsname* %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @sethostname(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = call i32 @uname(%struct.utsname* %2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @sleep(i32 1000)
ret i32 0
}