#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int execlp(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int create_term(char *hostname, int port) {
  pid_t pid;
  char port_str[32];
  char *uart_instance_prog = "/opt/skyeye/bin/uart_instance";
  sprintf(port_str, "%d", port);
  switch (pid = fork()) {
  case -1: {
    perror("The fork failed!");
    break;
  }
  case 0: {
    int ret =
        execlp("xterm", "xterm", "-e", uart_instance_prog, hostname, port_str);
    perror("Child:");
    fprintf(stderr, "SKYEYE Error:We need xterm to run the console of "
                    "uart.Please check if you installed it correctly.\n");
    _exit(-1);
  }
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edx
lea    0xe9a(%rip),%rsi
lea    -0x30(%rbp),%rdi
call   1060 <sprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x10(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x40(%rbp)
sub    $0xffffffff,%eax
je     11ba <create_term+0x5a>
jmp    11aa <create_term+0x4a>
mov    -0x40(%rbp),%eax
test   %eax,%eax
je     11cb <create_term+0x6b>
jmp    121b <create_term+0xbb>
lea    0xe60(%rip),%rdi
call   1050 <perror@plt>
jmp    1220 <create_term+0xc0>
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    0xe54(%rip),%rsi
lea    0xe53(%rip),%rdx
mov    %rsi,%rdi
call   1070 <execlp@plt>
mov    %eax,-0x3c(%rbp)
lea    0xe44(%rip),%rdi
call   1050 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
jmp    1220 <create_term+0xc0>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_term>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%edx
mov    %rdi,%rbx
lea    0xead(%rip),%rsi
mov    %rsp,%rdi
call   1060 <sprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     1191 <create_term+0x31>
test   %eax,%eax
je     119f <create_term+0x3f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
jmp    1189 <create_term+0x29>
lea    0xe8c(%rip),%rdi
lea    0xe8b(%rip),%rdx
lea    0xe4c(%rip),%rcx
mov    %rsp,%r9
mov    %rdi,%rsi
mov    %rbx,%r8
call   1070 <execlp@plt>
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"/opt/skyeye/bin/uart_instance\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"The fork failed!\00"
@.str.3 = [6 x i8] c"xterm\00"
@.str.4 = [3 x i8] c"-e\00"
@.str.5 = [7 x i8] c"Child:\00"
@stderr = global i32 0
@.str.6 = [99 x i8] c"SKYEYE Error:We need xterm to run the console of uart.Please check if you installed it correctly.\0A\00"
define i32 @create_term(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @fork()
store i32 %12, i32* %5
switch i32 %12, label %24 [
i32 -1, label %13
i32 0, label %15
]
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%19 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16, i8* %17, i8* %18)
store i32 %19, i32* %8
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @_exit(i32 -1)
unreachable
24: ; preds = %2
br label %25
25: ; preds = %24, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"/opt/skyeye/bin/uart_instance\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"The fork failed!\00"
@.str.3 = [6 x i8] c"xterm\00"
@.str.4 = [3 x i8] c"-e\00"
@.str.5 = [7 x i8] c"Child:\00"
@stderr = global i32 0
@.str.6 = [99 x i8] c"SKYEYE Error:We need xterm to run the console of uart.Please check if you installed it correctly.\0A\00"
define i32 @create_term(i8* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%6 = tail call i32 (...) @fork()
switch i32 %6, label %15 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %15
9: ; preds = %2
%10 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %4)
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @_exit(i32 -1)
unreachable
15: ; preds = %2, %7
ret i32 0
}