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

/* Variables and functions */
int /*<<< orphan*/ dirname(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ system(char *);
int upgrade_commands(char *argv, char *command) {
  char path[256];
  strncpy(path, argv, sizeof(path));
  dirname(path);
  char full_cmd[512];
  strncpy(full_cmd, "/bin/bash ", sizeof(full_cmd) - 1);
  strncat(full_cmd, path, sizeof(full_cmd) - 1);
  strncat(full_cmd, "/upgrade_commands.sh ", sizeof(full_cmd) - 1);
  strncat(full_cmd, command, sizeof(full_cmd) - 1);
  system(full_cmd);
}


x86 assembly (clang, -O0):
<upgrade_commands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x120(%rbp),%rdi
call   1050 <dirname@plt>
lea    -0x320(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
lea    -0x320(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
lea    -0x320(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
lea    -0x320(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
lea    -0x320(%rbp),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upgrade_commands>:
push   %r15
push   %r14
push   %rbx
sub    $0x300,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1050 <dirname@plt>
lea    0xe8f(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1ff,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
add    $0x300,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/bin/bash \00"
@.str.1 = [22 x i8] c"/upgrade_commands.sh \00"
define i32 @upgrade_commands(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 256)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @dirname(i8* %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 511)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i32 @strncat(i8* %15, i8* %16, i32 511)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%19 = call i32 @strncat(i8* %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 511)
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 @strncat(i8* %20, i8* %21, i32 511)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%24 = call i32 @system(i8* %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [11 x i8] c"/bin/bash \00"
@.str.1 = [22 x i8] c"/upgrade_commands.sh \00"
define i32 @upgrade_commands(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @strncpy(i8* %5, i8* %0, i32 256)
%7 = call i32 @dirname(i8* %5)
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 511)
%10 = call i32 @strncat(i8* %8, i8* %5, i32 511)
%11 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 511)
%12 = call i32 @strncat(i8* %8, i8* %1, i32 511)
%13 = call i32 @system(i8* %8)
ret i32 undef
}