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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char, char, char, char,
                           ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_help(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int vpdread_main(int argc, char **argv) {
  int fd, i = 0, found = 0;
  char ip[4];
  char mac[6];
  char path[64];
  FILE *f;
  int c;
  int option = -1;
  if (argc == 1) {
    print_help(argv[0]);
    exit(1);
  }
  while ((c = getopt(argc, argv, "ht")) != -1) {
    switch (c) {
    case 'h':
      print_help(argv[0]);
      exit(0);
      break;
    case 't':
      option = c;
      break;
    default:
      print_help(argv[0]);
      exit(1);
      break;
    }
  }
  if ((fd = open("/proc/mtd", O_RDONLY)) > 0) {
    f = fdopen(fd, "r");
    char line[64];
    fgets(line, sizeof(line), f);
    while (fgets(line, sizeof(line), f) != NULL) {
      if (strstr(line, " VPD") != NULL) {
        found = 1;
        break;
      }
      i++;
    }
    fclose(f);
    close(fd);
  }
  if (!found) {
    return -1;
  }
  snprintf(path, sizeof(path), "/dev/mtd%d", i);
  switch (option) {
  case 't':
    if ((fd = open(path, O_RDONLY)) < 0)
      return -1;
    lseek(fd, 11, SEEK_SET);
    if (read(fd, mac, 6) != 6) {
      close(fd);
      return -1;
    }
    lseek(fd, 0x3000, SEEK_SET);
    if (read(fd, ip, 4) != 4) {
      close(fd);
      return -1;
    }
    close(fd);
    f = fopen("/etc/tftp.config", "w");
    fprintf(f, "TFTP=%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
    fprintf(f, "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", mac[0], mac[1],
            mac[2], mac[3], mac[4], mac[5]);
    fclose(f);
    break;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<vpdread_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x80(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1227 <vpdread_main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <print_help@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    122c <vpdread_main+0x4c>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc6(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x7c(%rbp)
cmp    $0xffffffff,%eax
je     12af <vpdread_main+0xcf>
mov    -0x7c(%rbp),%eax
mov    %eax,-0xc4(%rbp)
sub    $0x68,%eax
je     1276 <vpdread_main+0x96>
jmp    1262 <vpdread_main+0x82>
mov    -0xc4(%rbp),%eax
sub    $0x74,%eax
je     1289 <vpdread_main+0xa9>
jmp    1294 <vpdread_main+0xb4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <print_help@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x80(%rbp)
jmp    12aa <vpdread_main+0xca>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <print_help@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    122c <vpdread_main+0x4c>
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
lea    0xd44(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    135f <vpdread_main+0x17f>
mov    -0x14(%rbp),%edi
lea    0xd33(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x78(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x40,%esi
call   1080 <fgets@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x40,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     134e <vpdread_main+0x16e>
lea    -0xc0(%rbp),%rdi
lea    0xcea(%rip),%rsi
call   1100 <strstr@plt>
cmp    $0x0,%rax
je     1340 <vpdread_main+0x160>
movl   $0x1,-0x1c(%rbp)
jmp    134e <vpdread_main+0x16e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12f8 <vpdread_main+0x118>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1375 <vpdread_main+0x195>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <vpdread_main+0x312>
mov    -0x18(%rbp),%ecx
lea    0xc95(%rip),%rdx
lea    -0x70(%rbp),%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
mov    -0x80(%rbp),%eax
sub    $0x74,%eax
jne    14e6 <vpdread_main+0x306>
jmp    139e <vpdread_main+0x1be>
lea    -0x70(%rbp),%rdi
mov    0x2c3f(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    13c8 <vpdread_main+0x1e8>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <vpdread_main+0x312>
mov    -0x14(%rbp),%edi
mov    0x2c06(%rip),%rax
mov    (%rax),%edx
mov    $0xb,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
je     140c <vpdread_main+0x22c>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <vpdread_main+0x312>
mov    -0x14(%rbp),%edi
mov    0x2bc2(%rip),%rax
mov    (%rax),%edx
mov    $0x3000,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0x4,%eax
je     1450 <vpdread_main+0x270>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <vpdread_main+0x312>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xbc0(%rip),%rdi
lea    0xbca(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x20(%rbp),%dl
mov    -0x1f(%rbp),%cl
mov    -0x1e(%rbp),%al
lea    0xbaf(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %al,%r8d
movsbl -0x1d(%rbp),%r9d
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x78(%rbp),%rdi
mov    -0x26(%rbp),%dl
mov    -0x25(%rbp),%cl
mov    -0x24(%rbp),%r8b
mov    -0x23(%rbp),%r9b
movsbl -0x22(%rbp),%r10d
movsbl -0x21(%rbp),%eax
lea    0xb89(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
jmp    14eb <vpdread_main+0x30b>
jmp    14eb <vpdread_main+0x30b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vpdread_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
je     1441 <vpdread_main+0x261>
mov    %edi,%ebp
xor    %ecx,%ecx
lea    0xdfb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   10d0 <getopt@plt>
mov    $0x1,%cl
cmp    $0x74,%eax
je     1210 <vpdread_main+0x30>
cmp    $0xffffffff,%eax
jne    142d <vpdread_main+0x24d>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdc4(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
jle    12d8 <vpdread_main+0xf8>
mov    %eax,%r14d
lea    0xdb7(%rip),%rsi
mov    %eax,%edi
call   10a0 <fdopen@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12c8 <vpdread_main+0xe8>
xor    %ebp,%ebp
lea    0xd7c(%rip),%r15
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
jne    12ee <vpdread_main+0x10e>
add    $0x1,%ebp
mov    %r13,%rdi
mov    $0x40,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    12a0 <vpdread_main+0xc0>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xd0f(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
xor    %ebp,%ebp
test   $0x1,%bl
je     12dd <vpdread_main+0xfd>
mov    0x2cc4(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     12d8 <vpdread_main+0xf8>
mov    %eax,%ebx
mov    0x2c9b(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %eax,%edi
mov    $0xb,%esi
call   1050 <lseek@plt>
lea    0xa(%rsp),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
jne    1426 <vpdread_main+0x246>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0x3000,%esi
call   1050 <lseek@plt>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebp
cmp    $0x4,%r14d
jne    12dd <vpdread_main+0xfd>
lea    0xc79(%rip),%rdi
lea    0xc83(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
movsbl 0x6(%rsp),%edx
movsbl 0x7(%rsp),%ecx
movsbl 0x8(%rsp),%r8d
movsbl 0x9(%rsp),%r9d
lea    0xc60(%rip),%rsi
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %eax,%eax
call   1090 <fprintf@plt>
movsbl 0xa(%rsp),%edx
movsbl 0xb(%rsp),%ecx
movsbl 0xc(%rsp),%r8d
movsbl 0xd(%rsp),%r9d
movsbl 0xe(%rsp),%r10d
movsbl 0xf(%rsp),%r11d
lea    0xc3d(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
push   %r11
push   %r10
call   1090 <fprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    12dd <vpdread_main+0xfd>
mov    %ebx,%edi
jmp    12d3 <vpdread_main+0xf3>
cmp    $0x68,%eax
jne    1441 <vpdread_main+0x261>
mov    (%r15),%rdi
call   10e0 <print_help@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    (%r15),%rdi
call   10e0 <print_help@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ht\00"
@.str.1 = [10 x i8] c"/proc/mtd\00"
@O_RDONLY = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c" VPD\00"
@.str.4 = [11 x i8] c"/dev/mtd%d\00"
@SEEK_SET = global i32 0
@.str.5 = [17 x i8] c"/etc/tftp.config\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [18 x i8] c"TFTP=%d.%d.%d.%d\0A\00"
@.str.8 = [41 x i8] c"MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\0A\00"
define i32 @vpdread_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8]
%10 = alloca [6 x i8]
%11 = alloca [64 x i8]
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca [64 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 -1, i32* %14
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @print_help(i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
br label %25
25: ; preds = %46, %24
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i32 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %28, i32* %13
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %47
30: ; preds = %25
%31 = load i32, i32* %13
switch i32 %31, label %40 [
i32 104, label %32
i32 116, label %38
]
32: ; preds = %30
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @print_help(i8* %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %30
%39 = load i32, i32* %13
store i32 %39, i32* %14
br label %46
40: ; preds = %30
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @print_help(i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
br label %25
47: ; preds = %25
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %48)
store i32 %49, i32* %6
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %75
51: ; preds = %47
%52 = load i32, i32* %6
%53 = call i32* @fdopen(i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %53, i32** %12
%54 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%55 = load i32*, i32** %12
%56 = call i32* @fgets(i8* %54, i32 64, i32* %55)
br label %57
57: ; preds = %67, %51
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%59 = load i32*, i32** %12
%60 = call i32* @fgets(i8* %58, i32 64, i32* %59)
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %70
62: ; preds = %57
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%64 = call i32* @strstr(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%65 = icmp ne i32* %64, null
br i1 %65, label %66, label %67
66: ; preds = %62
store i32 1, i32* %8
br label %70
67: ; preds = %62
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %57
70: ; preds = %66, %57
%71 = load i32*, i32** %12
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
br label %75
75: ; preds = %70, %47
%76 = load i32, i32* %8
%77 = icmp ne i32 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %75
store i32 -1, i32* %3
br label %146
79: ; preds = %75
%80 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%81 = load i32, i32* %7
%82 = call i32 @snprintf(i8* %80, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %14
switch i32 %83, label %144 [
i32 116, label %84
]
84: ; preds = %79
%85 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%86 = load i32, i32* @O_RDONLY
%87 = call i32 @open(i8* %85, i32 %86)
store i32 %87, i32* %6
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %84
store i32 -1, i32* %3
br label %146
90: ; preds = %84
%91 = load i32, i32* %6
%92 = load i32, i32* @SEEK_SET
%93 = call i32 @lseek(i32 %91, i32 11, i32 %92)
%94 = load i32, i32* %6
%95 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%96 = call i32 @read(i32 %94, i8* %95, i32 6)
%97 = icmp ne i32 %96, 6
br i1 %97, label %98, label %101
98: ; preds = %90
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
store i32 -1, i32* %3
br label %146
101: ; preds = %90
%102 = load i32, i32* %6
%103 = load i32, i32* @SEEK_SET
%104 = call i32 @lseek(i32 %102, i32 12288, i32 %103)
%105 = load i32, i32* %6
%106 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 4)
%108 = icmp ne i32 %107, 4
br i1 %108, label %109, label %112
109: ; preds = %101
%110 = load i32, i32* %6
%111 = call i32 @close(i32 %110)
store i32 -1, i32* %3
br label %146
112: ; preds = %101
%113 = load i32, i32* %6
%114 = call i32 @close(i32 %113)
%115 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %115, i32** %12
%116 = load i32*, i32** %12
%117 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%118 = load i8, i8* %117
%119 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%120 = load i8, i8* %119
%121 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%122 = load i8, i8* %121
%123 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%124 = load i8, i8* %123
%125 = call i32 (i32*, i8*, i8, i8, i8, i8, ...) @fprintf(i32* %116, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8 signext %118, i8 signext %120, i8 signext %122, i8 signext %124)
%126 = load i32*, i32** %12
%127 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%128 = load i8, i8* %127
%129 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 1
%130 = load i8, i8* %129
%131 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 2
%132 = load i8, i8* %131
%133 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 3
%134 = load i8, i8* %133
%135 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 4
%136 = load i8, i8* %135
%137 = sext i8 %136 to i32
%138 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 5
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = call i32 (i32*, i8*, i8, i8, i8, i8, ...) @fprintf(i32* %126, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8 signext %128, i8 signext %130, i8 signext %132, i8 signext %134, i32 %137, i32 %140)
%142 = load i32*, i32** %12
%143 = call i32 @fclose(i32* %142)
br label %145
144: ; preds = %79
br label %145
145: ; preds = %144, %112
store i32 0, i32* %3
br label %146
146: ; preds = %145, %109, %98, %89, %78
%147 = load i32, i32* %3
ret i32 %147
}

LLVM IR (-O2):
@.str = [3 x i8] c"ht\00"
@.str.1 = [10 x i8] c"/proc/mtd\00"
@O_RDONLY = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c" VPD\00"
@.str.4 = [11 x i8] c"/dev/mtd%d\00"
@SEEK_SET = global i32 0
@.str.5 = [17 x i8] c"/etc/tftp.config\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [18 x i8] c"TFTP=%d.%d.%d.%d\0A\00"
@.str.8 = [41 x i8] c"MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\0A\00"
define i32 @vpdread_main(i32 %0, i8** %1) {
%3 = alloca [4 x i8]
%4 = alloca [6 x i8]
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = tail call i32 @print_help(i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2, %15
%16 = phi i1 [ true, %15 ], [ false, %2 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %17, label %22 [
i32 -1, label %26
i32 104, label %18
i32 116, label %15
]
18: ; preds = %15
%19 = load i8*, i8** %1
%20 = tail call i32 @print_help(i8* %19)
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %15
%23 = load i8*, i8** %1
%24 = tail call i32 @print_help(i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %15
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %93
30: ; preds = %26
%31 = tail call i32* @fdopen(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%33 = call i32* @fgets(i8* %32, i32 64, i32* %31)
%34 = call i32* @fgets(i8* %32, i32 64, i32* %31)
%35 = icmp eq i32* %34, null
br i1 %35, label %90, label %36
36: ; preds = %30, %40
%37 = phi i32 [ %41, %40 ], [ 0, %30 ]
%38 = call i32* @strstr(i8* %32, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = add nuw nsw i32 %37, 1
%42 = call i32* @fgets(i8* %32, i32 64, i32* %31)
%43 = icmp eq i32* %42, null
br i1 %43, label %90, label %36
44: ; preds = %36
%45 = call i32 @fclose(i32* %31)
%46 = call i32 @close(i32 %28)
%47 = call i32 @snprintf(i8* %9, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br i1 %16, label %48, label %93
48: ; preds = %44
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* %9, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %93, label %52
52: ; preds = %48
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @lseek(i32 %50, i32 11, i32 %53)
%55 = call i32 @read(i32 %50, i8* %8, i32 6)
%56 = icmp eq i32 %55, 6
br i1 %56, label %59, label %57
57: ; preds = %52
%58 = call i32 @close(i32 %50)
br label %93
59: ; preds = %52
%60 = load i32, i32* @SEEK_SET
%61 = call i32 @lseek(i32 %50, i32 12288, i32 %60)
%62 = call i32 @read(i32 %50, i8* %7, i32 4)
%63 = icmp eq i32 %62, 4
%64 = call i32 @close(i32 %50)
br i1 %63, label %65, label %93
65: ; preds = %59
%66 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%67 = load i8, i8* %7
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%69 = load i8, i8* %68
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%71 = load i8, i8* %70
%72 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%73 = load i8, i8* %72
%74 = call i32 (i32*, i8*, i8, i8, i8, i8, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8 signext %67, i8 signext %69, i8 signext %71, i8 signext %73)
%75 = load i8, i8* %8
%76 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
%77 = load i8, i8* %76
%78 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
%79 = load i8, i8* %78
%80 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
%81 = load i8, i8* %80
%82 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = call i32 (i32*, i8*, i8, i8, i8, i8, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8 signext %75, i8 signext %77, i8 signext %79, i8 signext %81, i32 %84, i32 %87)
%89 = call i32 @fclose(i32* %66)
br label %93
90: ; preds = %40, %30
%91 = call i32 @fclose(i32* %31)
%92 = call i32 @close(i32 %28)
br label %93
93: ; preds = %59, %90, %26, %65, %44, %48, %57
%94 = phi i32 [ -1, %57 ], [ -1, %48 ], [ 0, %44 ], [ 0, %65 ], [ -1, %26 ], [ -1, %90 ], [ -1, %59 ]
ret i32 %94
}