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

/* Variables and functions */
int /*<<< orphan*/ copy_file(char *, char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ process_line(char *, char **, char **);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int main(int argn, char *argv[]) {
  char *command;
  char *path;
  char *library, *library_path;
  char line[1024], ldd[1024], copy[1024];
  FILE *in;
  if (argn < 3) {
    printf("%s command path\n\nCopy 'command' library dependences obtained "
           "with ldd to 'path'\n",
           argv[0]);
    return 0;
  }
  command = argv[1];
  path = argv[2];
  puts(command);
  puts(path);
  puts("\n");
  sprintf(ldd, "ldd \"%s\"", command);
  puts(ldd);
  in = popen(ldd, "r");
  if (in == NULL) {
    printf("Command %s not found\n", command);
    return 1;
  }
  while (!feof(in)) {
    if (NULL == fgets(line, sizeof(line), in))
      break;
    library = library_path = NULL;
    process_line(line, &library, &library_path);
    printf("library: %s library_path: %s\n", library, library_path);
    if (library != NULL) {
      if (library_path != NULL) {
        sprintf(copy, "%s/%s", path, library);
        copy_file(library_path, copy);
      } else {
        sprintf(copy, "%s/%s", path, library);
        copy_file(library, copy);
      }
    }
    puts("\n");
  }
  pclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139e <main+0x20e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x20(%rbp),%rdi
call   1040 <puts@plt>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
lea    -0x830(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x830(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x830(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0xc38(%rbp)
cmpq   $0x0,-0xc38(%rbp)
jne    1275 <main+0xe5>
mov    -0x18(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139e <main+0x20e>
jmp    127a <main+0xea>
mov    -0xc38(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    129b <main+0x10b>
jmp    138b <main+0x1fb>
lea    -0x430(%rbp),%rdi
mov    -0xc38(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12c6 <main+0x136>
jmp    138b <main+0x1fb>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10b0 <process_line@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     137a <main+0x1ea>
cmpq   $0x0,-0x30(%rbp)
je     1348 <main+0x1b8>
lea    -0xc30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
call   1030 <copy_file@plt>
jmp    1375 <main+0x1e5>
lea    -0xc30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
call   1030 <copy_file@plt>
jmp    137a <main+0x1ea>
lea    0xcce(%rip),%rdi
call   1040 <puts@plt>
jmp    127a <main+0xea>
mov    -0xc38(%rbp),%rdi
call   1060 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc28,%rsp
cmp    $0x2,%edi
jg     11be <main+0x2e>
mov    (%rsi),%rsi
lea    0xe50(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xc0>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rbx
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe6d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe63(%rip),%rsi
lea    0x420(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     123a <main+0xaa>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1264 <main+0xd4>
mov    %rbx,%rdi
call   1060 <pclose@plt>
xor    %ebx,%ebx
jmp    1250 <main+0xc0>
lea    0xe1b(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0xc28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x820(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbp
jmp    1298 <main+0x108>
nopl   0x0(%rax,%rax,1)
lea    0xdc8(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    122e <main+0x9e>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122e <main+0x9e>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10b0 <process_line@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xd90(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     1280 <main+0xf0>
cmpq   $0x0,0x8(%rsp)
mov    %rbp,%r13
cmove  %r12,%r13
lea    0x20(%rsp),%r14
mov    %r14,%rdi
lea    0xd81(%rip),%rsi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    0x0(%r13),%rdi
mov    %r14,%rsi
call   1030 <copy_file@plt>
jmp    1280 <main+0xf0>

LLVM IR (-O0):
@.str = [81 x i8] c"%s command path\0A\0ACopy 'command' library dependences obtained with ldd to 'path'\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"ldd \22%s\22\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [22 x i8] c"Command %s not found\0A\00"
@.str.5 = [30 x i8] c"library: %s library_path: %s\0A\00"
@.str.6 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 0, i32* %3
br label %90
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = call i32 @puts(i8* %28)
%30 = load i8*, i8** %7
%31 = call i32 @puts(i8* %30)
%32 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%37 = call i32 @puts(i8* %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%39 = call i32* @popen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %13
%40 = load i32*, i32** %13
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %21
%43 = load i8*, i8** %6
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %90
45: ; preds = %21
br label %46
46: ; preds = %85, %45
%47 = load i32*, i32** %13
%48 = call i32 @feof(i32* %47)
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br i1 %50, label %51, label %87
51: ; preds = %46
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%53 = load i32*, i32** %13
%54 = call i32* @fgets(i8* %52, i32 1024, i32* %53)
%55 = icmp eq i32* null, %54
br i1 %55, label %56, label %57
56: ; preds = %51
br label %87
57: ; preds = %51
store i8* null, i8** %9
store i8* null, i8** %8
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%59 = call i32 @process_line(i8* %58, i8** %8, i8** %9)
%60 = load i8*, i8** %8
%61 = load i8*, i8** %9
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %60, i8* %61)
%63 = load i8*, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %85
65: ; preds = %57
%66 = load i8*, i8** %9
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%70 = load i8*, i8** %7
%71 = load i8*, i8** %8
%72 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %70, i8* %71)
%73 = load i8*, i8** %9
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%75 = call i32 @copy_file(i8* %73, i8* %74)
br label %84
76: ; preds = %65
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%78 = load i8*, i8** %7
%79 = load i8*, i8** %8
%80 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %78, i8* %79)
%81 = load i8*, i8** %8
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%83 = call i32 @copy_file(i8* %81, i8* %82)
br label %84
84: ; preds = %76, %68
br label %85
85: ; preds = %84, %57
%86 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %46
87: ; preds = %56, %46
%88 = load i32*, i32** %13
%89 = call i32 @pclose(i32* %88)
store i32 0, i32* %3
br label %90
90: ; preds = %87, %42, %16
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str = [81 x i8] c"%s command path\0A\0ACopy 'command' library dependences obtained with ldd to 'path'\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"ldd \22%s\22\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [22 x i8] c"Command %s not found\0A\00"
@.str.5 = [30 x i8] c"library: %s library_path: %s\0A\00"
@.str.6 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast i8** %3 to i8*
%9 = bitcast i8** %4 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %58
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @puts(i8* dereferenceable(1) %19)
%23 = tail call i32 @puts(i8* dereferenceable(1) %21)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%26 = call i32 @puts(i8* %11)
%27 = call i32* @popen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %17
%30 = call i32 @feof(i32* %27)
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %56
32: ; preds = %17
%33 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %58
34: ; preds = %29, %52
%35 = call i32* @fgets(i8* %10, i32 1024, i32* %27)
%36 = icmp eq i32* %35, null
br i1 %36, label %56, label %37
37: ; preds = %34
store i8* null, i8** %4
store i8* null, i8** %3
%38 = call i32 @process_line(i8* %10, i8** %3, i8** %4)
%39 = load i8*, i8** %3
%40 = load i8*, i8** %4
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %39, i8* %40)
%42 = load i8*, i8** %3
%43 = icmp eq i8* %42, null
br i1 %43, label %52, label %44
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = icmp eq i8* %45, null
%47 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %21, i8* %42)
%48 = load i8*, i8** %4
%49 = load i8*, i8** %3
%50 = select i1 %46, i8* %49, i8* %48
%51 = call i32 @copy_file(i8* %50, i8* %12)
br label %52
52: ; preds = %44, %37
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = call i32 @feof(i32* %27)
%55 = icmp eq i32 %54, 0
br i1 %55, label %34, label %56
56: ; preds = %52, %34, %29
%57 = call i32 @pclose(i32* %27)
br label %58
58: ; preds = %56, %32, %14
%59 = phi i32 [ 0, %14 ], [ 1, %32 ], [ 0, %56 ]
ret i32 %59
}