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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
char *strdup(char *);
char *systemGetUniqueDeviceId(void) {
  char buf[32];
  char *retval = NULL;
  FILE *fp =
      popen("grep Serial /proc/cpuinfo | cut -f 2 -d : | tr -d \" \n\"", "r");
  if (fp == NULL) {
    return retval;
  }
  if (fgets(buf, sizeof(buf), fp) != NULL) {
    retval = strdup(buf);
  }
  pclose(fp);
  return retval;
}


x86 assembly (clang, -O0):
<systemGetUniqueDeviceId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x38(%rbp)
lea    0xea9(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    117f <systemGetUniqueDeviceId+0x3f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b9 <systemGetUniqueDeviceId+0x79>
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x20,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11a8 <systemGetUniqueDeviceId+0x68>
lea    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<systemGetUniqueDeviceId>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xeb2(%rip),%rdi
lea    0xee2(%rip),%rsi
call   1050 <popen@plt>
test   %rax,%rax
je     1184 <systemGetUniqueDeviceId+0x44>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1189 <systemGetUniqueDeviceId+0x49>
mov    %rsp,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
jmp    118c <systemGetUniqueDeviceId+0x4c>
xor    %r14d,%r14d
jmp    1194 <systemGetUniqueDeviceId+0x54>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [55 x i8] c"grep Serial /proc/cpuinfo | cut -f 2 -d : | tr -d \22 \0A\22\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @systemGetUniqueDeviceId() {
%1 = alloca i8*
%2 = alloca [32 x i8]
%3 = alloca i8*
%4 = alloca i32*
store i8* null, i8** %3
%5 = call i32* @popen(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i8*, i8** %3
store i8* %9, i8** %1
br label %22
10: ; preds = %0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32* @fgets(i8* %11, i32 32, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %3
br label %18
18: ; preds = %15, %10
%19 = load i32*, i32** %4
%20 = call i32 @pclose(i32* %19)
%21 = load i8*, i8** %3
store i8* %21, i8** %1
br label %22
22: ; preds = %18, %8
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [55 x i8] c"grep Serial /proc/cpuinfo | cut -f 2 -d : | tr -d \22 \0A\22\00"
@.str.1 = [2 x i8] c"r\00"
define noalias i8* @systemGetUniqueDeviceId() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 32, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i8* @strdup(i8* %2)
br label %10
10: ; preds = %8, %5
%11 = phi i8* [ %9, %8 ], [ null, %5 ]
%12 = call i32 @pclose(i32* %3)
br label %13
13: ; preds = %0, %10
%14 = phi i8* [ %11, %10 ], [ null, %0 ]
ret i8* %14
}