#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 {
  int /*<<< orphan*/ nodename;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ getpid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ setns(int, int /*<<< orphan*/);
int /*<<< orphan*/ uname(struct utsname *);
int main(int argc, char *argv[]) {
  int fd;
  struct utsname uts;
  if (argc < 2)
    return 1;
  fd = open(argv[1], O_RDONLY);
  setns(fd, 0);
  uname(&uts);
  printf("hostname of this (%ld): %s\n", (long)getpid(), uts.nodename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <setns@plt>
lea    -0x18(%rbp),%rdi
call   1060 <uname@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     11a0 <main+0x50>
mov    0x8(%rsi),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1050 <setns@plt>
lea    0x8(%rsp),%rdi
call   1060 <uname@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x8(%rsp),%edx
lea    0xe68(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@O_RDONLY = global i32 0
@.str = [28 x i8] c"hostname of this (%ld): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.utsname
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %24
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @setns(i32 %17, i32 0)
%19 = call i32 @uname(%struct.utsname* %7)
%20 = call i64 (...) @getpid()
%21 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %20, i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %11, %10
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@O_RDONLY = global i32 0
@.str = [28 x i8] c"hostname of this (%ld): %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = tail call i32 @setns(i32 %10, i32 0)
%12 = call i32 @uname(%struct.utsname* %3)
%13 = tail call i64 (...) @getpid()
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %13, i32 %15)
br label %17
17: ; preds = %2, %6
%18 = phi i32 [ 0, %6 ], [ 1, %2 ]
ret i32 %18
}