#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*/ execv(char *const, char *const *);
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ sethostname(char *, int);
int container_main(void *args) {
  char *const cmd[] = {"/bin/sh", NULL};
  printf("this is container process, pid=%d\n", getpid());
  if (sethostname("NewHostname", 11) < 0) {
    perror("set hostname failed");
    exit(1);
  }
  execv(cmd[0], cmd);
  return 0;
}


x86 assembly (clang, -O0):
<container_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2c9d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c9a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    $0xb,%esi
call   1050 <sethostname@plt>
cmp    $0x0,%rax
jge    11c8 <container_main+0x68>
lea    0xe7e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <execv@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<container_main>:
sub    $0x18,%rsp
movaps 0x2ca5(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0xb,%esi
call   1050 <sethostname@plt>
test   %rax,%rax
js     11b0 <container_main+0x50>
lea    0xe5f(%rip),%rdi
mov    %rsp,%rsi
call   1080 <execv@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@__const.container_main.cmd = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [35 x i8] c"this is container process, pid=%d\0A\00"
@.str.2 = [12 x i8] c"NewHostname\00"
@.str.3 = [20 x i8] c"set hostname failed\00"
define i32 @container_main(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i8*]
store i8* %0, i8** %2
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = call i32 (...) @getpid()
%6 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i64 @sethostname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%16 = call i32 @execv(i8* %14, i8** %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@__const.container_main.cmd = [2 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [35 x i8] c"this is container process, pid=%d\0A\00"
@.str.2 = [12 x i8] c"NewHostname\00"
@.str.3 = [20 x i8] c"set hostname failed\00"
define i32 @container_main(i8* nocapture readnone %0) {
%2 = alloca [2 x i8*]
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i64 @sethostname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%13 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %12)
ret i32 0
}