#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
int /*<<< orphan*/ system(char *);
char *get_usb_serial_num(char *part_name) {
  static char serial_num[128];
  char disk_name[8], path[64], line[128], cmd[256];
  char *bus_num = NULL;
  char *p;
  int j = 0;
  FILE *fp;
  serial_num[0] = '\0';
  snprintf(disk_name, 8, "%s", part_name);
  disk_name[3] = '\0';
  sprintf(cmd, "/bin/ls /sys/block/%s/device/scsi_device/ > /tmp/%s_info_tmp",
          disk_name, disk_name);
  system(cmd);
  sprintf(path, "/tmp/%s_info_tmp", disk_name);
  fp = fopen(path, "r");
  if (fp == NULL)
    goto ret;
  while (fgets(line, sizeof(line), fp)) {
    line[15] = '\0';
    char *tok = ":\n";
    bus_num = strtok(line, tok);
    fclose(fp);
  }
  if (bus_num != NULL) {
    snprintf(path, 64, "/proc/scsi/usb-storage/%s", bus_num);
    fp = fopen(path, "r");
    if (fp == NULL)
      goto ret;
    while (fgets(line, sizeof(line), fp)) {
      if (strncmp(line, "Serial Number:", 14) == 0) {
        while (line[j] != '\r' && line[j] != '\n')
          j++;
        line[j] = '\0';
        p = line + 14;
        while (*p != '\0')
          ++p;
        --p;
        while (*p == ' ' || *p == '\t')
          --p;
        *(p + 1) = '\0';
        p = line + 14;
        while (*p == ' ' || *p == '\t')
          p++;
        strcpy(serial_num, p);
      }
    }
  }
ret:
  if (fp != NULL)
    fclose(fp);
  return serial_num;
}


x86 assembly (clang, -O0):
<get_usb_serial_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x1d8(%rbp)
movl   $0x0,-0x1e4(%rbp)
movb   $0x0,0x2ec5(%rip)
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x8,%esi
lea    0xe8a(%rip),%rdx
call   1070 <snprintf@plt>
movb   $0x0,-0xd(%rbp)
lea    -0x1d0(%rbp),%rdi
lea    -0x10(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x1d0(%rbp),%rdi
call   1060 <system@plt>
lea    -0x50(%rbp),%rdi
lea    -0x10(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1f0(%rbp)
cmpq   $0x0,-0x1f0(%rbp)
jne    1241 <get_usb_serial_num+0xb1>
jmp    14fe <get_usb_serial_num+0x36e>
jmp    1246 <get_usb_serial_num+0xb6>
lea    -0xd0(%rbp),%rdi
mov    -0x1f0(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12a8 <get_usb_serial_num+0x118>
movb   $0x0,-0xc1(%rbp)
lea    0xdc9(%rip),%rax
mov    %rax,-0x1f8(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0x1f8(%rbp),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x1d8(%rbp)
mov    -0x1f0(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1246 <get_usb_serial_num+0xb6>
cmpq   $0x0,-0x1d8(%rbp)
je     14f9 <get_usb_serial_num+0x369>
lea    -0x50(%rbp),%rdi
mov    -0x1d8(%rbp),%rcx
mov    $0x40,%esi
lea    0xd75(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xd60(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1f0(%rbp)
cmpq   $0x0,-0x1f0(%rbp)
jne    12fc <get_usb_serial_num+0x16c>
jmp    14fe <get_usb_serial_num+0x36e>
jmp    1301 <get_usb_serial_num+0x171>
lea    -0xd0(%rbp),%rdi
mov    -0x1f0(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     14f4 <get_usb_serial_num+0x364>
lea    -0xd0(%rbp),%rdi
lea    0xd2b(%rip),%rsi
mov    $0xe,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14ef <get_usb_serial_num+0x35f>
jmp    134a <get_usb_serial_num+0x1ba>
movslq -0x1e4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x1f9(%rbp)
je     1385 <get_usb_serial_num+0x1f5>
movslq -0x1e4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1f9(%rbp)
mov    -0x1f9(%rbp),%al
test   $0x1,%al
jne    1398 <get_usb_serial_num+0x208>
jmp    13ac <get_usb_serial_num+0x21c>
mov    -0x1e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1e4(%rbp)
jmp    134a <get_usb_serial_num+0x1ba>
movslq -0x1e4(%rbp),%rax
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    -0xd0(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13f7 <get_usb_serial_num+0x267>
mov    -0x1e0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1e0(%rbp)
jmp    13cd <get_usb_serial_num+0x23d>
mov    -0x1e0(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x1fa(%rbp)
je     143a <get_usb_serial_num+0x2aa>
mov    -0x1e0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x1fa(%rbp)
mov    -0x1fa(%rbp),%al
test   $0x1,%al
jne    144d <get_usb_serial_num+0x2bd>
jmp    1464 <get_usb_serial_num+0x2d4>
mov    -0x1e0(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x1e0(%rbp)
jmp    1409 <get_usb_serial_num+0x279>
mov    -0x1e0(%rbp),%rax
movb   $0x0,0x1(%rax)
lea    -0xd0(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x1fb(%rbp)
je     14b2 <get_usb_serial_num+0x322>
mov    -0x1e0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x1fb(%rbp)
mov    -0x1fb(%rbp),%al
test   $0x1,%al
jne    14c5 <get_usb_serial_num+0x335>
jmp    14dc <get_usb_serial_num+0x34c>
mov    -0x1e0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1e0(%rbp)
jmp    1481 <get_usb_serial_num+0x2f1>
mov    -0x1e0(%rbp),%rsi
lea    0x2b96(%rip),%rdi
call   1040 <strcpy@plt>
jmp    1301 <get_usb_serial_num+0x171>
jmp    14f9 <get_usb_serial_num+0x369>
jmp    14fe <get_usb_serial_num+0x36e>
cmpq   $0x0,-0x1f0(%rbp)
je     1518 <get_usb_serial_num+0x388>
mov    -0x1f0(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2b61(%rip),%rax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_usb_serial_num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1d8,%rsp
mov    %rdi,%rcx
movb   $0x0,0x2ed5(%rip)
lea    0xea7(%rip),%rdx
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <snprintf@plt>
movb   $0x0,0xb(%rsp)
lea    0xe30(%rip),%rsi
lea    0xd0(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <system@plt>
lea    0xe35(%rip),%rsi
lea    0x90(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xe2a(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     13c4 <get_usb_serial_num+0x234>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13bc <get_usb_serial_num+0x22c>
lea    0xdf6(%rip),%r14
lea    0x10(%rsp),%r15
xchg   %ax,%ax
movb   $0x0,0x1f(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    1250 <get_usb_serial_num+0xc0>
test   %rbx,%rbx
je     13bc <get_usb_serial_num+0x22c>
lea    0xdb2(%rip),%rdx
lea    0x90(%rsp),%r14
mov    %r14,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1070 <snprintf@plt>
lea    0xd8e(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     13c4 <get_usb_serial_num+0x234>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13bc <get_usb_serial_num+0x22c>
xor    %ebp,%ebp
lea    0x1d(%rsp),%rbx
lea    0xd70(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x2d88(%rip),%r12
jmp    1319 <get_usb_serial_num+0x189>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13bc <get_usb_serial_num+0x22c>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xe,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1300 <get_usb_serial_num+0x170>
movslq %ebp,%rax
add    %rsp,%rax
add    $0x10,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
cmp    $0xa,%cl
je     1360 <get_usb_serial_num+0x1d0>
cmp    $0xd,%cl
je     1360 <get_usb_serial_num+0x1d0>
add    $0x1,%rax
add    $0x1,%ebp
jmp    1340 <get_usb_serial_num+0x1b0>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rax)
mov    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rax)
lea    0x1(%rax),%rax
jne    1370 <get_usb_serial_num+0x1e0>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
add    $0xffffffffffffffff,%rax
movzbl -0x1(%rcx),%edx
cmp    $0x9,%dl
je     1380 <get_usb_serial_num+0x1f0>
cmp    $0x20,%dl
je     1380 <get_usb_serial_num+0x1f0>
movb   $0x0,(%rcx)
lea    0x1e(%rsp),%rsi
jmp    13a4 <get_usb_serial_num+0x214>
nop
add    $0x1,%rsi
movzbl (%rsi),%eax
cmp    $0x20,%al
je     13a0 <get_usb_serial_num+0x210>
cmp    $0x9,%al
je     13a0 <get_usb_serial_num+0x210>
mov    %r12,%rdi
call   1040 <strcpy@plt>
jmp    1300 <get_usb_serial_num+0x170>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0x2cb5(%rip),%rax
add    $0x1d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_usb_serial_num.serial_num = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@.str.1 = [61 x i8] c"/bin/ls /sys/block/%s/device/scsi_device/ > /tmp/%s_info_tmp\00"
@.str.2 = [17 x i8] c"/tmp/%s_info_tmp\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c":\0A\00"
@.str.5 = [26 x i8] c"/proc/scsi/usb-storage/%s\00"
@.str.6 = [15 x i8] c"Serial Number:\00"
define i8* @get_usb_serial_num(i8* %0) {
%2 = alloca i8*
%3 = alloca [8 x i8]
%4 = alloca [64 x i8]
%5 = alloca [128 x i8]
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %7
store i32 0, i32* %9
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0)
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @snprintf(i8* %12, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
store i8 0, i8* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32 @system(i8* %20)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %1
br label %143
30: ; preds = %1
br label %31
31: ; preds = %36, %30
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%33 = load i32*, i32** %10
%34 = call i64 @fgets(i8* %32, i32 128, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 15
store i8 0, i8* %37
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %11
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%39 = load i8*, i8** %11
%40 = call i8* @strtok(i8* %38, i8* %39)
store i8* %40, i8** %7
%41 = load i32*, i32** %10
%42 = call i32 @fclose(i32* %41)
br label %31
43: ; preds = %31
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %142
46: ; preds = %43
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%48 = load i8*, i8** %7
%49 = call i32 @snprintf(i8* %47, i32 64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %51, i32** %10
%52 = load i32*, i32** %10
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %55
54: ; preds = %46
br label %143
55: ; preds = %46
br label %56
56: ; preds = %140, %55
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%58 = load i32*, i32** %10
%59 = call i64 @fgets(i8* %57, i32 128, i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %141
61: ; preds = %56
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 14)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %140
65: ; preds = %61
br label %66
66: ; preds = %82, %65
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 13
br i1 %72, label %73, label %80
73: ; preds = %66
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp ne i32 %78, 10
br label %80
80: ; preds = %73, %66
%81 = phi i1 [ false, %66 ], [ %79, %73 ]
br i1 %81, label %82, label %85
82: ; preds = %80
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 1
store i32 %84, i32* %9
br label %66
85: ; preds = %80
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%90 = getelementptr inbounds i8, i8* %89, i64 14
store i8* %90, i8** %8
br label %91
91: ; preds = %96, %85
%92 = load i8*, i8** %8
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i8*, i8** %8
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %8
br label %91
99: ; preds = %91
%100 = load i8*, i8** %8
%101 = getelementptr inbounds i8, i8* %100, i32 -1
store i8* %101, i8** %8
br label %102
102: ; preds = %114, %99
%103 = load i8*, i8** %8
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 32
br i1 %106, label %112, label %107
107: ; preds = %102
%108 = load i8*, i8** %8
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = icmp eq i32 %110, 9
br label %112
112: ; preds = %107, %102
%113 = phi i1 [ true, %102 ], [ %111, %107 ]
br i1 %113, label %114, label %117
114: ; preds = %112
%115 = load i8*, i8** %8
%116 = getelementptr inbounds i8, i8* %115, i32 -1
store i8* %116, i8** %8
br label %102
117: ; preds = %112
%118 = load i8*, i8** %8
%119 = getelementptr inbounds i8, i8* %118, i64 1
store i8 0, i8* %119
%120 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%121 = getelementptr inbounds i8, i8* %120, i64 14
store i8* %121, i8** %8
br label %122
122: ; preds = %134, %117
%123 = load i8*, i8** %8
%124 = load i8, i8* %123
%125 = sext i8 %124 to i32
%126 = icmp eq i32 %125, 32
br i1 %126, label %132, label %127
127: ; preds = %122
%128 = load i8*, i8** %8
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 9
br label %132
132: ; preds = %127, %122
%133 = phi i1 [ true, %122 ], [ %131, %127 ]
br i1 %133, label %134, label %137
134: ; preds = %132
%135 = load i8*, i8** %8
%136 = getelementptr inbounds i8, i8* %135, i32 1
store i8* %136, i8** %8
br label %122
137: ; preds = %132
%138 = load i8*, i8** %8
%139 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0), i8* %138)
br label %140
140: ; preds = %137, %61
br label %56
141: ; preds = %56
br label %142
142: ; preds = %141, %43
br label %143
143: ; preds = %142, %54, %29
%144 = load i32*, i32** %10
%145 = icmp ne i32* %144, null
br i1 %145, label %146, label %149
146: ; preds = %143
%147 = load i32*, i32** %10
%148 = call i32 @fclose(i32* %147)
br label %149
149: ; preds = %146, %143
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0)
}

LLVM IR (-O2):
@get_usb_serial_num.serial_num = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@.str.1 = [61 x i8] c"/bin/ls /sys/block/%s/device/scsi_device/ > /tmp/%s_info_tmp\00"
@.str.2 = [17 x i8] c"/tmp/%s_info_tmp\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c":\0A\00"
@.str.5 = [26 x i8] c"/proc/scsi/usb-storage/%s\00"
@.str.6 = [15 x i8] c"Serial Number:\00"
define i8* @get_usb_serial_num(i8* %0) {
%2 = alloca [8 x i8]
%3 = alloca [64 x i8]
%4 = alloca [128 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0)
%10 = call i32 @snprintf(i8* %6, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 0, i8* %11
%12 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %6)
%13 = call i32 @system(i8* %9)
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%15 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %78, label %17
17: ; preds = %1
%18 = call i64 @fgets(i8* %8, i32 128, i32* %15)
%19 = icmp eq i64 %18, 0
br i1 %19, label %75, label %20
20: ; preds = %17
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 15
br label %22
22: ; preds = %20, %22
store i8 0, i8* %21
%23 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @fclose(i32* %15)
%25 = call i64 @fgets(i8* %8, i32 128, i32* %15)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = icmp eq i8* %23, null
br i1 %28, label %75, label %29
29: ; preds = %27
%30 = call i32 @snprintf(i8* %7, i32 64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%31 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %78, label %33
33: ; preds = %29
%34 = call i64 @fgets(i8* %8, i32 128, i32* %31)
%35 = icmp eq i64 %34, 0
br i1 %35, label %75, label %36
36: ; preds = %33
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 14
br label %38
38: ; preds = %36, %71
%39 = phi i32 [ 0, %36 ], [ %72, %71 ]
%40 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 14)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %71
42: ; preds = %38
%43 = sext i32 %39 to i64
br label %44
44: ; preds = %42, %48
%45 = phi i64 [ %43, %42 ], [ %49, %48 ]
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %45
%47 = load i8, i8* %46
switch i8 %47, label %48 [
i8 13, label %50
i8 10, label %50
]
48: ; preds = %44
%49 = add i64 %45, 1
br label %44
50: ; preds = %44, %44
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %45
%52 = trunc i64 %45 to i32
store i8 0, i8* %51
br label %53
53: ; preds = %53, %50
%54 = phi i8* [ %37, %50 ], [ %57, %53 ]
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 0
%57 = getelementptr inbounds i8, i8* %54, i64 1
br i1 %56, label %58, label %53
58: ; preds = %53, %62
%59 = phi i8* [ %60, %62 ], [ %54, %53 ]
%60 = getelementptr inbounds i8, i8* %59, i64 -1
%61 = load i8, i8* %60
switch i8 %61, label %63 [
i8 32, label %62
i8 9, label %62
]
62: ; preds = %58, %58
br label %58
63: ; preds = %58
store i8 0, i8* %59
br label %64
64: ; preds = %67, %63
%65 = phi i8* [ %37, %63 ], [ %68, %67 ]
%66 = load i8, i8* %65
switch i8 %66, label %69 [
i8 32, label %67
i8 9, label %67
]
67: ; preds = %64, %64
%68 = getelementptr inbounds i8, i8* %65, i64 1
br label %64
69: ; preds = %64
%70 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0), i8* %65)
br label %71
71: ; preds = %69, %38
%72 = phi i32 [ %52, %69 ], [ %39, %38 ]
%73 = call i64 @fgets(i8* %8, i32 128, i32* %31)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %38
75: ; preds = %71, %17, %33, %27
%76 = phi i32* [ %15, %27 ], [ %31, %33 ], [ %15, %17 ], [ %31, %71 ]
%77 = call i32 @fclose(i32* %76)
br label %78
78: ; preds = %29, %1, %75
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_usb_serial_num.serial_num, i64 0, i64 0)
}