#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int system(char *);
int main(int argc, char *argv[]) {
  char *cmd;
  int sts = 0;
  cmd = (char *)malloc(strlen(argv[0]) + 5 + sizeof(".term"));
  if (cmd) {
    strcpy(cmd, "open ");
    strcat(&cmd[5], argv[0]);
    strcat(cmd, ".term");
    sts = system(cmd);
  }
  return sts;
}


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)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
add    $0x5,%eax
cltq
add    $0x6,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d8 <main+0x88>
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
add    $0x5,%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rsi),%rdi
call   1040 <strlen@plt>
lea    0xb(%rax),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ab <main+0x5b>
mov    %rax,%rbx
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
add    $0x5,%rdi
mov    (%r14),%rsi
call   1070 <strcat@plt>
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"open \00"
@.str.1 = [6 x i8] c".term\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 5
%13 = sext i32 %12 to i64
%14 = add i64 %13, 6
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %33
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 5
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @strcat(i8* %24, i8* %27)
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8*, i8** %6
%32 = call i32 @system(i8* %31)
store i32 %32, i32* %7
br label %33
33: ; preds = %20, %2
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"open \00"
@.str.1 = [6 x i8] c".term\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strlen(i8* %3)
%5 = add i32 %4, 11
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds i8, i8* %7, i64 5
%12 = load i8*, i8** %1
%13 = tail call i32 @strcat(i8* %11, i8* %12)
%14 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @system(i8* %7)
br label %16
16: ; preds = %9, %2
%17 = phi i32 [ %15, %9 ], [ 0, %2 ]
ret i32 %17
}