#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 uintptr_t uintmax_t;
typedef int /*<<< orphan*/ ocbuf;
typedef int /*<<< orphan*/ caddr_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int LINE_MAX;
int PATH_MAX;
int /*<<< orphan*/ err(int, char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strcmp(char *, char *);
uintptr_t strtoumax(char *, int /*<<< orphan*/ *, int);
int tokenize(char *, char **, int);
void doobj(const char *path, caddr_t addr, FILE *out) {
  uintmax_t base = (uintptr_t)addr;
  uintmax_t textaddr = 0;
  uintmax_t dataaddr = 0;
  uintmax_t bssaddr = 0;
  uintmax_t *up;
  int octokens;
  char *octoken[10];
  char ocbuf[LINE_MAX + PATH_MAX];
  FILE *objcopy;
  snprintf(ocbuf, sizeof(ocbuf), "/usr/bin/objdump --section-headers %s", path);
  if ((objcopy = popen(ocbuf, "r")) == NULL)
    err(2, "can't start %s", ocbuf);
  while (fgets(ocbuf, sizeof(ocbuf), objcopy)) {
    octokens = tokenize(ocbuf, octoken, 10);
    if (octokens <= 1)
      continue;
    up = NULL;
    if (strcmp(octoken[1], ".text") == 0)
      up = &textaddr;
    else if (strcmp(octoken[1], ".data") == 0)
      up = &dataaddr;
    else if (strcmp(octoken[1], ".bss") == 0)
      up = &bssaddr;
    if (up == NULL)
      continue;
    *up = strtoumax(octoken[3], NULL, 16) + base;
  }
  if (textaddr) {
    fprintf(out, "add-symbol-file %s 0x%jx", path, textaddr);
    if (dataaddr)
      fprintf(out, " -s .data 0x%jx", dataaddr);
    if (bssaddr)
      fprintf(out, " -s .bss 0x%jx", bssaddr);
    fprintf(out, "\n");
  }
}


x86 assembly (clang, -O0):
<doobj>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%ecx
add    %ecx,%eax
mov    %rax,-0xc8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xc0(%rbp)
mov    %rdi,%rsp
mov    %rax,-0xb0(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xdf6(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0xc0(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0xb8(%rbp)
cmp    $0x0,%rax
jne    124b <doobj+0xcb>
mov    -0xc0(%rbp),%rdx
mov    $0x2,%edi
lea    0xde2(%rip),%rsi
call   1070 <err@plt>
jmp    1250 <doobj+0xd0>
mov    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rax
mov    %eax,%esi
mov    -0xb8(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1363 <doobj+0x1e3>
mov    -0xc0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0xa,%edx
call   1080 <tokenize@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jg     12a0 <doobj+0x120>
jmp    1250 <doobj+0xd0>
movq   $0x0,-0x40(%rbp)
mov    -0x98(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12d2 <doobj+0x152>
lea    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    132b <doobj+0x1ab>
mov    -0x98(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12fc <doobj+0x17c>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1326 <doobj+0x1a6>
mov    -0x98(%rbp),%rdi
lea    0xd39(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1321 <doobj+0x1a1>
lea    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1326 <doobj+0x1a6>
jmp    132b <doobj+0x1ab>
cmpq   $0x0,-0x40(%rbp)
jne    133b <doobj+0x1bb>
jmp    1250 <doobj+0xd0>
mov    -0x88(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoumax@plt>
mov    %rax,%rcx
add    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
jmp    1250 <doobj+0xd0>
cmpq   $0x0,-0x28(%rbp)
je     13dc <doobj+0x25c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
je     13a9 <doobj+0x229>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xcbf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpq   $0x0,-0x38(%rbp)
je     13ca <doobj+0x24a>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xcab(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xa8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doobj>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rcx
mov    %rsp,-0x58(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e10(%rip),%rax
mov    0x2e19(%rip),%rdx
mov    (%rdx),%r12d
add    (%rax),%r12d
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe0a(%rip),%rdx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %rcx,-0x50(%rbp)
call   1030 <snprintf@plt>
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <popen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1230 <doobj+0xa0>
lea    0xe05(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1080 <err@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     135e <doobj+0x1ce>
mov    %r15,-0x48(%rbp)
movslq %r14d,%rax
mov    %rax,-0x60(%rbp)
lea    -0xb0(%rbp),%r14
jmp    128d <doobj+0xfd>
nopl   0x0(%rax,%rax,1)
mov    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoumax@plt>
add    -0x60(%rbp),%rax
mov    %rax,(%r15)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12fb <doobj+0x16b>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1090 <tokenize@plt>
cmp    $0x2,%eax
jl     127a <doobj+0xea>
mov    -0xa8(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1060 <strcmp@plt>
lea    -0x40(%rbp),%r15
test   %rax,%rax
je     1260 <doobj+0xd0>
mov    -0xa8(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1060 <strcmp@plt>
lea    -0x38(%rbp),%r15
test   %rax,%rax
je     1260 <doobj+0xd0>
mov    -0xa8(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   1060 <strcmp@plt>
lea    -0x30(%rbp),%r15
test   %rax,%rax
jne    127a <doobj+0xea>
jmp    1260 <doobj+0xd0>
mov    -0x40(%rbp),%rcx
test   %rcx,%rcx
mov    -0x48(%rbp),%rbx
je     135e <doobj+0x1ce>
lea    0xd39(%rip),%rsi
mov    %rbx,%rdi
mov    -0x50(%rbp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdx
test   %rdx,%rdx
je     1337 <doobj+0x1a7>
lea    0xd34(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdx
test   %rdx,%rdx
je     1351 <doobj+0x1c1>
lea    0xd2a(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    -0x58(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LINE_MAX = global i32 0
@PATH_MAX = global i32 0
@.str = [38 x i8] c"/usr/bin/objdump --section-headers %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"can't start %s\00"
@.str.3 = [6 x i8] c".text\00"
@.str.4 = [6 x i8] c".data\00"
@.str.5 = [5 x i8] c".bss\00"
@.str.6 = [25 x i8] c"add-symbol-file %s 0x%jx\00"
@.str.7 = [16 x i8] c" -s .data 0x%jx\00"
@.str.8 = [15 x i8] c" -s .bss 0x%jx\00"
@.str.9 = [2 x i8] c"\0A\00"
define void @doobj(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64*
%12 = alloca i32
%13 = alloca [10 x i8*]
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
store i64 %18, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
%19 = load i32, i32* @LINE_MAX
%20 = load i32, i32* @PATH_MAX
%21 = add nsw i32 %19, %20
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %14
%24 = alloca i8, i64 %22
store i64 %22, i64* %15
%25 = trunc i64 %22 to i32
%26 = load i8*, i8** %4
%27 = call i32 @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32* @popen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %16
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %3
%31 = call i32 @err(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %32
32: ; preds = %30, %3
br label %33
33: ; preds = %68, %67, %43, %32
%34 = trunc i64 %22 to i32
%35 = load i32*, i32** %16
%36 = call i64 @fgets(i8* %24, i32 %34, i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %75
38: ; preds = %33
%39 = getelementptr inbounds [10 x i8*], [10 x i8*]* %13, i64 0, i64 0
%40 = call i32 @tokenize(i8* %24, i8** %39, i32 10)
store i32 %40, i32* %12
%41 = load i32, i32* %12
%42 = icmp sle i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %38
br label %33
44: ; preds = %38
store i64* null, i64** %11
%45 = getelementptr inbounds [10 x i8*], [10 x i8*]* %13, i64 0, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
store i64* %8, i64** %11
br label %64
50: ; preds = %44
%51 = getelementptr inbounds [10 x i8*], [10 x i8*]* %13, i64 0, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %50
store i64* %9, i64** %11
br label %63
56: ; preds = %50
%57 = getelementptr inbounds [10 x i8*], [10 x i8*]* %13, i64 0, i64 1
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %56
store i64* %10, i64** %11
br label %62
62: ; preds = %61, %56
br label %63
63: ; preds = %62, %55
br label %64
64: ; preds = %63, %49
%65 = load i64*, i64** %11
%66 = icmp eq i64* %65, null
br i1 %66, label %67, label %68
67: ; preds = %64
br label %33
68: ; preds = %64
%69 = getelementptr inbounds [10 x i8*], [10 x i8*]* %13, i64 0, i64 3
%70 = load i8*, i8** %69
%71 = call i64 @strtoumax(i8* %70, i32* null, i32 16)
%72 = load i64, i64* %7
%73 = add i64 %71, %72
%74 = load i64*, i64** %11
store i64 %73, i64* %74
br label %33
75: ; preds = %33
%76 = load i64, i64* %8
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %99
78: ; preds = %75
%79 = load i32*, i32** %6
%80 = load i8*, i8** %4
%81 = load i64, i64* %8
%82 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %80, i64 %81)
%83 = load i64, i64* %9
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %78
%86 = load i32*, i32** %6
%87 = load i64, i64* %9
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 %87)
br label %89
89: ; preds = %85, %78
%90 = load i64, i64* %10
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i32*, i32** %6
%94 = load i64, i64* %10
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i64 %94)
br label %96
96: ; preds = %92, %89
%97 = load i32*, i32** %6
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %99
99: ; preds = %96, %75
%100 = load i8*, i8** %14
ret void
}

LLVM IR (-O2):
@LINE_MAX = global i32 0
@PATH_MAX = global i32 0
@.str = [38 x i8] c"/usr/bin/objdump --section-headers %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"can't start %s\00"
@.str.3 = [6 x i8] c".text\00"
@.str.4 = [6 x i8] c".data\00"
@.str.5 = [5 x i8] c".bss\00"
@.str.6 = [25 x i8] c"add-symbol-file %s 0x%jx\00"
@.str.7 = [16 x i8] c" -s .data 0x%jx\00"
@.str.8 = [15 x i8] c" -s .bss 0x%jx\00"
define void @doobj(i8* %0, i32 %1, i32* nocapture %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca [10 x i8*]
%8 = sext i32 %1 to i64
%9 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%10 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%11 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%12 = bitcast [10 x i8*]* %7 to i8*
%13 = load i32, i32* @LINE_MAX
%14 = load i32, i32* @PATH_MAX
%15 = add nsw i32 %14, %13
%16 = zext i32 %15 to i64
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @snprintf(i8* %18, i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = call i32* @popen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @err(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %24
24: ; preds = %22, %3
%25 = call i64 @fgets(i8* %18, i32 %15, i32* %20)
%26 = icmp eq i64 %25, 0
br i1 %26, label %70, label %27
27: ; preds = %24
%28 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%29 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 1
%30 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 3
br label %31
31: ; preds = %27, %51
%32 = call i32 @tokenize(i8* %18, i8** %28, i32 10)
%33 = icmp slt i32 %32, 2
br i1 %33, label %51, label %34
34: ; preds = %31
%35 = load i8*, i8** %29
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i8*, i8** %29
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i8*, i8** %29
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %42, %34, %38
%47 = phi i64* [ %5, %38 ], [ %4, %34 ], [ %6, %42 ]
%48 = load i8*, i8** %30
%49 = call i64 @strtoumax(i8* %48, i32* null, i32 16)
%50 = add i64 %49, %8
store i64 %50, i64* %47
br label %51
51: ; preds = %46, %31, %42
%52 = call i64 @fgets(i8* %18, i32 %15, i32* %20)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %31
54: ; preds = %51
%55 = load i64, i64* %4
%56 = icmp eq i64 %55, 0
br i1 %56, label %70, label %57
57: ; preds = %54
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %0, i64 %55)
%59 = load i64, i64* %5
%60 = icmp eq i64 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %57
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 %59)
br label %63
63: ; preds = %61, %57
%64 = load i64, i64* %6
%65 = icmp eq i64 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %63
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i64 %64)
br label %68
68: ; preds = %66, %63
%69 = call i32 @fputc(i32 10, i32* %2)
br label %70
70: ; preds = %24, %68, %54
ret void
}